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!
 
One of those two methods should work for you Mark. Here is a 3rd method.

Notice that the ChDrive and ChDir command do not contain ()'s as shown in Andrew's code. You may need to check your path for the X: drive. Andrew assumed that it was just the \\network part. If you use ()'s, prefix with the Call command. e.g.

Code:
Sub Save_File()
  'Save Changes to the current book in its current location
  ThisWorkbook.Save
  
  'Change directory to default Location where x: is the mapped drive
  Call ChDrive("x")
  Call ChDir("x:\mark\files")
  
  'Open SaveAs Window so that the user can save a copy in the other directory
  Application.Dialogs(xlDialogSaveAs).Show
End Sub

I prefer to use the method as Andrew explained.

Here is the 3rd method:
Code:
Sub Test()
  SaveAs ThisWorkbook.path & "\Test.xls"
End Sub

Sub SaveAs(initialFilename As String)
  With Application.FileDialog(msoFileDialogSaveAs)
    .AllowMultiSelect = False
    .ButtonName = "&Save As"
    .initialFilename = initialFilename
    .Title = "File Save As"
    .Execute
    .Show
  End With
End Sub
 
Upvote 0

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

Forum statistics

Threads
1,216,073
Messages
6,128,646
Members
449,462
Latest member
Chislobog

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