Change File Name On Network Drive

Espy

New Member
Joined
Aug 29, 2011
Messages
2
Hi, I'm trying to rename a file with VBA so that the original file and the reviewed file are on the network drive in the same folder.

P:\Compliance\4000\RD2\RG Round 2.xls is compared to P:\Compliance\4000\RD1\RG Round 1.xls to identify which cells have changed.

P:\Compliance\4000\RD2\RG Round 2.xls should then be saved as P:\Compliance\4000\RD2\Checked RG Round 2.xls so that we have the original and the version with changed cells highlighted.

The code I'm using is failing at ActiveWorkbook.SaveAs.

Code:
Sub ChangeFileName()
 
    Dim sFileNameChange As String
    Dim sFile3 As String
    sFileNameChange = ActiveWorkbook.FullName
    sNewFileSplit = Right(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewPathSplit = Left(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewFileSplit2 = "Checked " & sNewFileSplit
    sNewPathSplit2 = sNewPathSplit & "\"
    sFile3 = sNewPathSplit2 & sNewFileSplit2
    ActiveWorkbook.SaveAs Filename:=sFile3, FileFormat:=xlExcel8
 
End Sub

Thanks in advance.

Steve
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
I didn't actually let it attempt the save, but your code shows me a double backslash in the middle of the filename when I add the MsgBox as shown below.

Gary

Code:
Sub ChangeFileName()
 
    Dim sFileNameChange As String
    Dim sFile3 As String
    sFileNameChange = ActiveWorkbook.FullName
    sNewFileSplit = Right(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewPathSplit = Left(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewFileSplit2 = "Checked " & sNewFileSplit
    sNewPathSplit2 = sNewPathSplit & "\"
    sFile3 = sNewPathSplit2 & sNewFileSplit2
    
    [COLOR=Red]MsgBox sFile3[/COLOR]

    ActiveWorkbook.SaveAs Filename:=sFile3, FileFormat:=xlExcel8
    
End Sub
 
Upvote 0
I didn't actually let it attempt the save, but your code shows me a double backslash in the middle of the filename when I add the MsgBox as shown below.

Gary

Code:
Sub ChangeFileName()
 
    Dim sFileNameChange As String
    Dim sFile3 As String
    sFileNameChange = ActiveWorkbook.FullName
    sNewFileSplit = Right(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewPathSplit = Left(sFileNameChange, Len(sFileNameChange) - InStrRev(sFileNameChange, "\"))
    sNewFileSplit2 = "Checked " & sNewFileSplit
    sNewPathSplit2 = sNewPathSplit & "\"
    sFile3 = sNewPathSplit2 & sNewFileSplit2
 
    [COLOR=red]MsgBox sFile3[/COLOR]
 
    ActiveWorkbook.SaveAs Filename:=sFile3, FileFormat:=xlExcel8
 
End Sub

Thanks - I don't get the double backslash when I run it (I added the MsgBox to check the file name).
 
Upvote 0
I'm using XL 2000. If I send sFile3 to the debug window I get:

Brand new file (never been saved):

Book1\Checked Book1


File saved as "Book1.xls" in "C:\Temp"

C:\Temp\\Checked Book1.xls

I don't know why it would be different on another machine unless it has something to do with the Excel version.


Maybe try it like this:

Code:
ThisWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & "Checked " & ThisWorkbook.Name, FileFormat:=xlExcel8

Also double check, or maybe even eliminate, "FileFormat"

Gary
 
Upvote 0

Forum statistics

Threads
1,224,532
Messages
6,179,388
Members
452,908
Latest member
MTDelphis

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