0

I've been searching over the web for solution on how to open file using Open File Dialog in VBScript. Can someone point me on the right track?

My code below opens Excel file but I wanted it to be more dynamic in terms that the input file name can be change and not hard coded.

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"
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
  • have a look at this [answer](http://stackoverflow.com/a/21565999/3802503) , might help you – Karthikeyan Vedi Aug 24 '16 at 06:24
  • Hi Karthikeyan! Thanks for your response. I was able to used the code in the link you provide but I am looking for a more vb definite one which is native to excel file dialog. – Alvin Gasta Aug 25 '16 at 07:36

1 Answers1

0

When in doubt, read the 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
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328