ChDir Not Working

markf5998

Board Regular
Joined
Jan 13, 2011
Messages
103
I've tried solutions found through searching google, but nothing seems to make "chdir" do what I want it to do. Any help would be greatly appreciated!

my code looks like this:

chdir \\network\mark's folders\file location
Application.Dialogs(xlDialogSaveAs).Show


I wanted the saveas dialog box to default to the location that I specified through chdir, but when the dialog box opens, it is at the normal default location (c:\...\my documents)

The code runs without any errors.

Any ideas?

Thanks!
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I tried chdrive("[path]") but I'm getting an "Invalid procedure call" error when it runs. It looks like the syntax should be the same for chdrive as it is for chdir, should it be different?
 
Upvote 0
The network drive is mapped as x:, so I tried:

chdrive("x")

with and without

chdir ("[path]")

But still get the same results, saveas dialog is not defaulted to the desired location.

I read through the link (thank you for sending!) but it is a little out of my range...When I try to insert the "Declare Function..." line at the top of the module as was suggested, it immediately turns red and when I try to run it pups up a box for me to select a different macro. Also tried to paste the entire code that was suggested towards the end of the post, with similar results.
 
Upvote 0
Thanks for the response, but still the same result...this is my entire code, if it helps:

Sub Save_File()<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
'Save Changes to the current book in its current location<o:p></o:p>
ThisWorkbook.Save<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
'Change directory to default Location where x: is the mapped drive<o:p></o:p>
ChDrive "x"<o:p></o:p>
ChDir ("\\network\ops\mark\files")<o:p></o:p>
<o:p> </o:p>
'Open SaveAs Window so that the user can save a copy in the other directory<o:p></o:p>
Application.Dialogs(xlDialogSaveAs).Show<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
End Sub
 
Upvote 0
What is x mapped to? Something like this worked for me:

Code:
    ChDrive "x"
    ChDir "x:\ops\mark\files"
    Application.Dialogs(xlDialogSaveAs).Show
 
Upvote 0
Maybe try something like this...

Code:
fileSaveName = Application.GetSaveAsFilename( _
               InitialFileName:="\\network\ops\mark\files", _
               FileFilter:="Excel Files (*.xls), *.xls")
               
If fileSaveName <> False Then
    MsgBox "Save as " & fileSaveName
End If
 
Upvote 0
Andrew - X is mapped to "network"...I tried the code you wrote and it is doing the same thing. Also tried it removing "network" from the chdir line, since we already (maybe) covered that part by changing the drive. Clearly I am still an ametuer at this!

AlphaFrog - This did what I was looking for!

Thank you both for helping me out, greatly appreciated!!
 
Upvote 0

Forum statistics

Threads
1,214,808
Messages
6,121,686
Members
449,048
Latest member
81jamesacct

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