Forum Discussion

Lorenzo Kim's avatar
Lorenzo Kim
Bronze Contributor
Aug 08, 2018
Solved

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 West's avatar
    Philip West
    Iron 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 Kim's avatar
      Lorenzo Kim
      Bronze Contributor
      Mr. West
      It worked perfectly!!
      Thank you very much.

Resources