%userprofile% problem

ScottyWm

Board Regular
Joined
Jan 10, 2004
Messages
105
I've got a macro that saves a file to a local folder. Worked flawlessly in XP. Now they've moved us to Win10 and it doesn't work. The file was going to the C:\Windows\Temp\filename Folder, which we no longer have permission to access. So, I tried changing the path to C:\%userprofile%\documents\filename folder. But I get an error '1004': "Microsoft Excel cannot access the file 'C:\%userprofile%\Documents\CA50B420'." I've tried changing syntax around but nothing helped. And I have no idea why it's trying to access CA50B420.

I thought this would be an easy change, now I'm left scratching my head...
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try using the path this way. It works in Windows 7, but not sure if in Windows 10....

"C:\Users" & Environ("UserName") & "\Documents\filename.xls"
 
Upvote 0
Or maybe
Code:
Environ("userprofile") & "\documents\"
 
Upvote 0
Well, y'all pointed me in the right direction. After trying a few different things this is what worked for me:

' New Win10 code
ActiveWorkbook.SaveAs Filename:= _
Environ("userprofile") & "\documents" & "Scorecard", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False, ConflictResolution:=2

Thanks for the help! This is such a great forum...
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,985
Members
452,540
Latest member
haasro02

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