如何在 vba 中显示用户表单上的所有工作表?

如何在 vba 中显示用户表单上的所有工作表?

我使用我的代码打开工作簿,选择工作簿后,我想提示用户表单,该表单将显示属于该工作簿的所有工作表。这是我的代码:

Function WorksheetExists(WSName As String) As Boolean
   On Error Resume Next
       WorksheetExists = Worksheets(WSName).Name = WSName
       On Error GoTo 0
End Function

Sub Button1_Click()
  Dim shname As String, ssname As String
  Dim wb As String, wc As String
  wc = Application.GetOpenFilename
   If wc <> "False" Then Workbooks.Open wc
     Do Until WorksheetExists(ssname)
      ssname = InputBox("Enter sheet name")
       If Not WorksheetExists(ssname) Then
          MsgBox ssname & " doesn't exist!", vbExclamation
       Else
         WSName = ssname

         Sheets(ssname).Select
       End If
       Loop
End Sub

相关内容