CHDIR vba

daveyc18

Well-known Member
Joined
Feb 11, 2013
Messages
787
Office Version
  1. 365
  2. 2010
CHDir Path

the path is definitely correct...when I do ?path and copy and paste the path to an explorer window, the path opens up

however, when I run the macro to open a file in the path, it opens "My Documents"

this is the code after Chdir path

filetoopen = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
How are you loading Path? I loaded it this way

VBA Code:
Sub OpenFileFromPath()
  Dim Path As String
  Dim FileToOpen As Variant
  
  Path = ThisWorkbook.Path
  Debug.Print Path
  
  ChDir Path
  
  FileToOpen = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*")
  
End Sub
 
Upvote 0
ChDir only works if your current directory is on the same drive. If not, you need ChDrive to change the relevant drive first.
 
Upvote 0

Forum statistics

Threads
1,225,743
Messages
6,186,770
Members
453,370
Latest member
juliewar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top