I am trying to use ChDir in Excel VBA to change the default directory to the one the current workbook is located, so that I can have the macro open an open file dialog box with that same folder as the default.
I can't get it to work properly, my code below gives a runtime error saying the path not found.
Dim myPath As String
myPath = ActiveWorkbook.Path
ChDrive ""
ChDir myPath 'this line gives the error
OpenFiles = Application.GetOpenFilename(Title:="select file(s) to import", MultiSelect:=True)
I'm working in a Onedrive folder, which seems to be the problem (it works ok if I move the workbook to my desktop.) How can I get around this problem? I want to be able to use this macro regardless of where the workbook is located.