我尝试了多种方法在列表框中选择多个工作表,然后将选定的工作表名称返回到msgbox。谁能帮忙做到这一点。
目前,我能够在列表框中填充工作表名称。但是,我没有在msgbox中获得所有选定的工作表名称。
Public listChoice As String
Private Sub UserForm_Activate()
For n = 1 To ActiveWorkbook.Sheets.Count
With ListBox1
.AddItem ActiveWorkbook.Sheets(n).Name
End With
Next n
End Sub
Private Sub ListBox1_AfterUpdate()
listChoice = ListBox1.Text
End Sub
Private Sub CommandButton1_Click()
MsgBox (listChoice)
End Sub
在列表框中获取所选项目并不像您希望的那样简单:
Private Sub CommandButton1_Click()
Dim Msg As String
Dim i As Integer
Msg = "You selected" & vbNewLine
For i = 0 To ListBox1.ListCount - 1
If ListBox1.Selected(i) Then
Msg = Msg & ListBox1.List(i) & vbNewLine
End If
Next i
MsgBox Msg
End Sub
信用:http : //www.java2s.com/Code/VBA-Excel-Access-Word/Forms/GettheselecteditemsinaListBox.htm
您不需要使用此代码的ListBox1_AfterUpdate()
Sub或publiclistChoice
变量
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句