0

我一直在网上搜索有关如何使用 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"
4

1 回答 1

0

如有疑问,请阅读文档

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
于 2016-08-24T08:07:23.053 回答