以下是源码:
Private Sub Command0_Click() ' 打开文件选择对话框 With Application.FileDialog(msoFileDialogFilePicker) .AllowMultiSelect = False .Filters.Clear .Filters.Add "Excel 文件", "*.xls; *.xlsx", 1 If .Show = -1 Then filePath = .SelectedItems(1) Else Exit Sub ' 用户取消选择 End If End With End Sub
运行后报错
查看语法 ,并没有发现问题
解决方案:
Application.FileDialog直接传入参数的"值",而不是"名称",即:Application.FileDialog(3)
额外提示,很多能在EXCEL VBA中正常运行的代码,到了ACCESS VBA里面,参数类型往往是需要改成数值类型的,这里我这几年的工作经验,希望能帮助大家
标签:VBA,End,Sub,ACCESS,Application,FileDialog From: https://www.cnblogs.com/yoooos/p/18086562