common code to save a file on the desktop in different systems

RAJESH1960

Banned for repeated rules violations
Joined
Mar 26, 2020
Messages
2,313
Office Version
  1. 2019
Platform
  1. Windows
Hello Guys,
I want to share a workbook which has VBA protected codes with many people. It has a macro which converts the excel to XMLand saves it on the desktop. It works fine in my system.
When I share the file the other user is not able to save the file on his desktop. But gets an error. Is there a common code to save the macro on desktop in different systems.??
This is my code to save the file on my desktop.
strTempFile = "C:\Users\Admin\Desktop\importSales.xml"
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Try
Code:
Usr=Environ("username")

strTempFile = "C:\Users\" & Usr & "\Desktop\importSales.xml"

Also Windows Scripting
 
Upvote 0
Try
Code:
Usr=Environ("username")

strTempFile = "C:\Users\" & Usr & "\Desktop\importSales.xml"

Also Windows Scripting
I am getting a compile error. variable not defined
 
Last edited:
Upvote 0
Daverunt, I added an extra line at the top and got it working. Thanks

Dim usr As String
 
Upvote 0
I was just getting to that!
If you use Option Explicit you have to define the variable.
 
Upvote 0

Forum statistics

Threads
1,214,971
Messages
6,122,520
Members
449,088
Latest member
RandomExceller01

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