title: How do I use a variable path when using ChDir in an Excel Macro?
body: <p>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.</p>
  <p>I can't get it to work properly, my code below gives a runtime error saying the path not found.</p>
  <pre><code>Dim myPath As String
  myPath = ActiveWorkbook.Path
  ChDrive &quot;&quot;
  ChDir myPath  'this line gives the error
  OpenFiles = Application.GetOpenFilename(Title:=&quot;select file(s) to import&quot;, MultiSelect:=True)
  </code></pre>
  <p>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.</p>