Help with Saving a file with an invalid path

UMAKEMESIK

Active Member
Joined
Oct 3, 2005
Messages
378
I am trying to save a file to a path on my company's network. When I type in this line in my - run box in windows it recognizes it and takes me to the proper folder.

Now I am trying to save to that same folder with a specified file name.

excel does not like this line and can not find the path.

Code:
"\\fp_slz\users\%username%\sr.xls" _

Is there something in the above line that does not work in excel, does it not like some of the characters?

Below is the full saving command.

Code:
Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
            "\\fp_slz\users\%username%\sr.xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True

Any help would be appreciated.
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
I think you'd be fine with one tweak:
Code:
Application.DisplayAlerts = False
ThisWorkbook.SaveAs ("\\fp_slz\users\%username%\sr.xls")
Application.DisplayAlerts = True
 
Upvote 0
I don't think it's going to recognise %username%, which as far as I know is how you would include an environment variable like username.

When you do type this in Windows what's the actual name of the folder it takes you to?

The %username% should have been replaced with an actual user name.

You can use Environ("username") to get the username in VBA and then incorporate that in the path.

Something like this perhaps:
Rich (BB code):
strUserName = Environ("username")
 
strPath = \\fp_slz\users\" & strUserName% & "\sr.xls"
 
Upvote 0
Thanks for all the help.

Here is what I was able to get to work:

Code:
With Sheets(1)
        strUserName = Environ("username")
End With

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
            strPath = "\\fpslz\users\" & strUserName & "\sr.xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True

I took out the %. They seemed to be giving me errors. Everything test out fine on my first couple of test.

THANKS AGAIN!!!!!
 
Upvote 0
OOPS, SPOKE TO SOON.

The code just flys by this like it's not even there

Code:
With Sheets(1)
        strUserName = Environ("username")
End With

Application.DisplayAlerts = False
ActiveWorkbook.SaveAs Filename:= _
            strPath = "\\fpslz\users\" & strUserName & "\sr.xls" _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
Application.DisplayAlerts = True

Any formatting help would be appreciated.
 
Upvote 0
When I type in this line in my - run box in windows it recognizes it and takes me to the proper folder.
What shows in the address bar when the folder opens?
 
Upvote 0
@UMake You have this in your last post:
Code:
ActiveWorkbook.SaveAs Filename:= _
           [COLOR="Red"] strPath = "\\fpslz\users\" & strUserName & "\sr.xls"[/COLOR] _
        , FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False


That's not exactly what Norie provided as an example.
It should be this:
Code:
strUserName = Environ("username")
strPath = "\\fpslz\users\" & strUserName & "\sr.xls"
ActiveWorkbook.SaveAs Filename:= strPath, _
        FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
        ReadOnlyRecommended:=False, CreateBackup:=False
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,730
Members
452,939
Latest member
WCrawford

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