Changing the directory using ChDir

azizrasul

Well-known Member
Joined
Jul 7, 2003
Messages
1,304
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
Why does ChDir not change the directory in the following code?

Code:
    ChDrive "C"
    ChDir Nz("C:\Users\Aziz\Desktop", "")

    strFilePathandName = objExcelApp.Application.GetOpenFilename(Title:="SELECT MS EXCEL FILE", FileFilter:="Excel Files *.xls* (*.xls*),")
 
Unfortunately this is not the expected behavior of the method I suggested. There is no Excel object that will attempt opening an Excel file in the code or any kind of trigger. In fact, there is basically nothing to do with the Excel in this code and method other than the file filter which basically also has nothing to do with the Excel but only file extension as string value.

May be your Office version has something to do with it or something that I am really missing but it still doesn't make sense since it works as expected in my computer (Office 365). I am really not sure, but here is the Microsoft VBA reference page for the method for more information. Note that you can only use this method to select file or folder in Access. Open or Save parameters are even not valid to be used in Access.
 
Upvote 0

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
I'm using MS Office 2013, although I can't see why that would make a difference. The link you sent looks good. I'll investigate that. If not successful, then will have to live with the fact that I will have to go to the folder and select the file. Thanks for your help.
 
Upvote 0
the only thing I can think of is if explorer is set up to somehow respond to single clicks instead of double clicks (for opening files). Not sure if that would apply to file dialogs though (really shouldn't...!)
 
Upvote 0
I have noticed that sometimes the Password Dialog box appears while in other times it doesn't. Curious.
If I Compact & Repair the db, then it doesn't appear.
 
Upvote 0

Forum statistics

Threads
1,215,633
Messages
6,125,922
Members
449,274
Latest member
mrcsbenson

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