如何在ComboBox中排除.xlsb文件类型?

时间:2015-06-08 20:51:02

标签: excel excel-vba combobox vba

我有一个Userform,它基本上是两个由打开的工作簿填充的组合框。有没有办法可以从这个列表中排除PERSONAL.XLSB?这就是我所拥有的:

Sub UserForm_Initialize()
Dim wkb As Workbook
With Me.ComboBox1
    For Each wkb In Application.Workbooks
        .AddItem wkb.Name
    Next wkb
End With
With Me.ComboBox2
    For Each wkb In Application.Workbooks
        .AddItem wkb.Name
    Next wkb
End With
End Sub

1 个答案:

答案 0 :(得分:2)

With Me.ComboBox1
    For Each wkb In Application.Workbooks
        If Not Right(wkb.Name, 4) = "xlsb" Then
            .AddItem wkb.Name
        End If
    Next wkb
End With

如果您不想依赖文件扩展名可见,则可以检查文件格式。

If Not wkb.FileFormat = 50 Then
   .AddItem wkb.Name
End If