Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vba 我的用户表单中没有commandbutton1可以吗?_Vba_Excel_Userform - Fatal编程技术网

Vba 我的用户表单中没有commandbutton1可以吗?

Vba 我的用户表单中没有commandbutton1可以吗?,vba,excel,userform,Vba,Excel,Userform,我有一个Excel中userform的vba代码。这个用户表单允许我显示一个列表框,其中显示所有可用的工作表。。。然后在我的列表框中选择所需的工作表后,通过在我的用户表单中单击一个名为“CommandButton1”的按钮,它会选择所需的工作表。。。然而,我只想在我的列表框中选择并点击我想要的工作表,它就会选择我想要的工作表(这样,我就不需要再点击我的用户表单中的“CommandButton1”按钮来选择我想要的工作表了)…如果有人能帮我,那将是非常棒的。。非常感谢。哈维请在下面找到我的代码:

我有一个Excel中userform的vba代码。这个用户表单允许我显示一个列表框,其中显示所有可用的工作表。。。然后在我的列表框中选择所需的工作表后,通过在我的用户表单中单击一个名为“CommandButton1”的按钮,它会选择所需的工作表。。。然而,我只想在我的列表框中选择并点击我想要的工作表,它就会选择我想要的工作表(这样,我就不需要再点击我的用户表单中的“CommandButton1”按钮来选择我想要的工作表了)…如果有人能帮我,那将是非常棒的。。非常感谢。哈维请在下面找到我的代码:

Sub CommandButton1_Click()

    Worksheets(ListBox1.Value).Select
End Sub

Sub UserForm_Initialize()
    Dim n As Integer
    Dim msg As String

    On Error GoTo Exit
    Do
        n = n + 1
        ListBox1.AddItem Sheets(n).Name
    Loop Until n = Worksheets.Count

    If ListBox1.Value.Selected Then
        CommandButton1_Click = True
    Else
        CommandButton1_Click = False
    End If
    Exit:

End Sub

您所需要的只是列表框
单击
事件处理程序:

Option Explicit

Private Sub ListBox1_Click()
    With Me.ListBox1
        If .ListIndex <> -1 Then Worksheets(.Value).Select
    End With
End Sub



Sub UserForm_Initialize()
    Dim n As Integer

    Do
        n = n + 1
        ListBox1.AddItem Sheets(n).Name
    Loop Until n = Worksheets.Count

End Sub
放置工作表(ListBox1.Value)。在ListBox1\u Click()事件中选择。
Sub UserForm_Initialize()
    Dim sht As Worksheet

    For Each sht In Worksheets
        ListBox1.AddItem sht.Name
    Next
End Sub