首页 > 解决方案 > 用户表单组合框不会显示所有打开的 Excel 工作簿

问题描述

我正在尝试创建一个用户窗体,其中所有打开的 Excel 工作簿都显示在组合框中,但由于某种原因,尽管有几个工作簿清楚地打开,但组合框的下拉列表中没有显示结果。

这是用户窗体的代码

Option Explicit

Private Sub CommandButton1_Click()
    MyFile = Me.SourceSlate.Value
    Unload Me
End Sub

Private Sub CommandButton2_Click()
    Hide
    Stopped = True
    Unload Me
End Sub

Private Sub SourceSlate_UserForm_Initialize()
    Dim wkb As Workbook
    Me.Label.Caption = "Select the Source slate from the list of open Excel Workbooks below"
    With Me.SourceSlate
        For Each wkb In Application.Workbooks
            .AddItem wkb.Name
        Next wkb
    End With
End Sub

这是模块运行用户窗体的代码

Option Explicit

Public MyFile As String
Public Stopped As Boolean

Sub SourceSlate_UserForm()

    Stopped = False

    SourceSlate.Show

    If Stopped Then Exit Sub
End Sub

任何帮助是极大的赞赏!!!

标签: excelvbacomboboxuserform

解决方案


推荐阅读