我想创建一个宏,允许用户从他/她的本地浏览和定位文件,然后对拉取的文件执行一些功能来拉取文件。
我不确定如何在宏中合并浏览文件功能。
使用Application.FileDialog
,在SO和互联网上的其他地方有很多例子,例如这里
下面的将打开并设置 wkbFileToOpen,然后您将能够将其用作您的工作簿进行操作。
Dim vFileToOpen As Variant
Dim wkbFileToOpen As Workbook
'Ask the user to select the file, you can change your desired file extensions and file types
vFileToOpen = Application.GetOpenFilename("Excel Files (*.xls),*.xls,", 1, "Select the workbook", , False)
'if the user cancels, then vFileToOpen will be false, so we need to check there's a value
If Not vFileToOpen Then
Workbooks.Open vFileToOpen
Set wkbFileToOpen = ActiveWorkbook
End If