Change Directory Line Isn't Working Right

bigt88

New Member
Joined
Jul 28, 2011
Messages
2
Newb here. So I've made an excel workbook for log sheets for the company I'm interning at. Simply put, the plant operators use the sheet to log equipment conditions every 2 hours using a save macro button. It's been working great, but the problem I have is that the change directory macro isn't working (or isn't working the way I'd expect it to). There are two operators that use the same computer, so every now and then the macro saves the file in the wrong place.

Here is the save portion of the macro:
Option Explicit
Sub SvAs()
'Saves filename as value of W22 plus the current date \\Prnts2\dryerlog\West Curd Log\electronic log sheet\

MsgBox "Saving Log Book to the Server"
Dim newFile As String, fName As String
fName = Range("W22").Value
newFile = fName & " " & Format$(Date, "mm-dd-yyyy")
'Directory Change
ChDir "\\Prnts2\dryerlog\West Curd Log\electronic log sheet"
'
ActiveWorkbook.SaveAs Filename:=newFile

Does anyone have any ideas on why it isn't changing the directory? Sometimes it works if I run the macro a few times in a row. Thanks in advance!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
Maybe

Code:
'Directory Change
ChDrive "\\Prnts2\"
ChDir "\\Prnts2\dryerlog\West Curd Log\electronic log sheet"
 
Upvote 0
If you put the whole path into the file name then you don't need to change the directory.

Option Explicit
Sub SvAs()
'Saves filename as value of W22 plus the current date \\Prnts2\dryerlog\West Curd Log\electronic log sheet\

MsgBox "Saving Log Book to the Server"
Dim newFile As String, fName As String
fName = Range("W22").Value
newFile = "\\Prnts2\dryerlog\West Curd Log\electronic log sheet\" & fName & " " & Format$(Date, "mm-dd-yyyy")
ActiveWorkbook.SaveAs Filename:=newFile
 
Upvote 0
Thanks guys. I didn't try adding the change drive code, but Philip's revised code seems to be working after testing it a few times. You guys are awesome!
 
Upvote 0

Forum statistics

Threads
1,224,591
Messages
6,179,767
Members
452,940
Latest member
rootytrip

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