Forum Discussion
Lorenzo Kim
Aug 08, 2018Bronze Contributor
dialog box to open at active path
In the snippet below - how do I make the dialog box open at the active path or where the workbook was opened.
many many thanks
Dim strFileToOpen As String
*** vba to declare the active path
strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", FileFilter:="Excel Files *.xls* (*.xls*),")
Workbooks.Open Filename:=strFileToOpen
Set targetedWB = Workbooks.Open(strFileToOpen)
Dim strFileToOpen As String
ChDrive Left(ActiveWorkbook.Path, 1)
ChDir ActiveWorkbook.Path
strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", FileFilter:="Excel Files *.xls* (*.xls*),")
Workbooks.Open Filename:=strFileToOpen
Set targetedWB = Workbooks.Open(strFileToOpen)This should do it I think.. If you know the drive letter will be the same every time then you can replace that left() with just the letter..
2 Replies
- Philip WestIron Contributor
Dim strFileToOpen As String
ChDrive Left(ActiveWorkbook.Path, 1)
ChDir ActiveWorkbook.Path
strFileToOpen = Application.GetOpenFilename _
(Title:="Please choose a file to open", FileFilter:="Excel Files *.xls* (*.xls*),")
Workbooks.Open Filename:=strFileToOpen
Set targetedWB = Workbooks.Open(strFileToOpen)This should do it I think.. If you know the drive letter will be the same every time then you can replace that left() with just the letter..
- Lorenzo KimBronze ContributorMr. West
It worked perfectly!!
Thank you very much.