编译错误帮助并在用户窗体上将标题居中

时间:2018-07-20 01:43:21

标签: excel-vba

以下代码给了我一个编译错误。 “编译错误:错误的参数数量或无效的属性分配”该错误似乎发生在.Filters.Add上 如果有帮助,.Add将以蓝色突出显示。

此外,如何将标题文本放在用户表单的中心。

Private Sub cmdBrowse_Click()

'myFile = Application.GetOpenFilename(, , "Select a File.")

Dim fname As String
Dim fpath As String

fpath = ThisWorkbook.Path

With Application.FileDialog(msoFileDialogOpen)
    .InitialFileName = fpath
    .ButtonName = "Get File Name"
    .Title = "File Selection"
    .Filters.Clear
    .Filters.Add "*.xl", "*.xlsx", "*.xlsm", "*.xlb", "*.xlam", "*.xltx", "*.xltm", "*.xls", "*.xla", "*.xlt", "*.xlm", "*.xlw"
    .AllowMultiSelect = False

    If .Show = True Then
        fname = .SelectedItems(1)
        Me.TextBox1.Text = fname
    Else
        MsgBox "Operation Canceled"
    End If
End With
End Sub

谢谢

1 个答案:

答案 0 :(得分:0)

Filter.Add有三个论点。您提供了12个参数。更改为.Filters.Add "Excel", "*.xl; *.xlsx; *.xlsm; *.xlb; *.xlam; *.xltx; *.xltm; *.xls; *.xla; *.xlt; *.xlm; *.xlw",它应该可以正常工作。