如何使用打开文件对话框打开文件
How to open file using Open File Dialog
我一直在网上搜索有关如何在 VBScript 中使用“打开文件对话框”打开文件的解决方案。有人能指出我正确的方向吗?
我下面的代码打开 Excel 文件,但我希望它在输入文件名可以更改而不是硬编码方面更加动态。
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = 0
Set objShell = WScript.CreateObject("WScript.Shell")
path = objShell.CurrentDirectory
inFileName = "InputFile.xlsx"
inFilePath = path + "\" + inFileName
'Open target workbook
Set objWorkbook1 = objExcel.Workbooks.Open(inFilePath, False, True)
MsgBox "Reading Data from " & inFileName & vbNewLine, vbOkOnly + vbInformation, _
"Reading Data"
如有疑问,请阅读 documentation。
Set dialog = objExcel.FileDialog(3)
dialog.AllowMultiSelect = True
dialog.Show
For Each f In dialog.SelectedItems
Set objWorkbook = objExcel.Workbooks.Open(f)
'... do stuff ...
objWorkbook.Close
Next
我一直在网上搜索有关如何在 VBScript 中使用“打开文件对话框”打开文件的解决方案。有人能指出我正确的方向吗?
我下面的代码打开 Excel 文件,但我希望它在输入文件名可以更改而不是硬编码方面更加动态。
Set objExcel = CreateObject("Excel.Application")
objExcel.DisplayAlerts = 0
Set objShell = WScript.CreateObject("WScript.Shell")
path = objShell.CurrentDirectory
inFileName = "InputFile.xlsx"
inFilePath = path + "\" + inFileName
'Open target workbook
Set objWorkbook1 = objExcel.Workbooks.Open(inFilePath, False, True)
MsgBox "Reading Data from " & inFileName & vbNewLine, vbOkOnly + vbInformation, _
"Reading Data"
如有疑问,请阅读 documentation。
Set dialog = objExcel.FileDialog(3)
dialog.AllowMultiSelect = True
dialog.Show
For Each f In dialog.SelectedItems
Set objWorkbook = objExcel.Workbooks.Open(f)
'... do stuff ...
objWorkbook.Close
Next