VBA to save to desktop

BTA1322

New Member
Joined
Jul 21, 2024
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello

I had help from this group many years ago and all worked perfect , however, the company has now moved to 365 and the macro does not now run - it stops at the save section. I have recorded a macro using the function in excel. I require the VBA to save to the desktop on any pc by any users

Old Code
Dim strUser As String
strUser = Environ("UserName")

Application.DisplayAlerts = False

ActiveWorkbook.SaveAs Filename:= _
"C:\Documents and Settings\" & strUser & "\Desktop\Carrier Files\Book1.xlsx", _
FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close



New Recorded code - using the record function excel 365

ChDir _
"C:\Users\username\OneDrive\OneDrive - CompanyName\Desktop\Carrier Files"
ActiveWorkbook.SaveAs Filename:= _
"https://compantnamel-my.sharepoint....me/Documents/Desktop/Carrier Files/Book1.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False


Any help/direction will be appreciated

Many thanks

Brian
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
it stops at the save section.
I presume you are referring to the new code, not the old. You must be getting an error message - in that case, best to post the number and message.
AFAIK, you cannot use vba to directly save to a web url (including SharePoint). You need to get the UNC path to the server and use that. If you can create your own mapping to the server (e.g. map M drive) you will find it in the properties sheet for the mapping. Or you can ask the server admin. The UNC path will begin with \\ followed by the server name.
 
Upvote 0
Hello Micron

Yes, reffering to the New recoreded code. The macro stops running at the first line C/User etc. So if I understand correctly, I am unable to set-up a macro to save to desktop owing to using sharepoint without the companies I.T authorisation etc. ?

New recorded code
ChDir _
"C:\Users\MyName\OneDrive\OneDrive - CompanyName\Desktop\Carrier Files"
ActiveWorkbook.SaveAs Filename:= _
"https://companyname-my.sharepoint.com/personal/" & strUser & "/Desktop/Carrier%20Files/Book1.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
ActiveWindow.Close
 
Upvote 0
Hi *BTA1322. This link might help. Dave
 
Upvote 0

Forum statistics

Threads
1,224,884
Messages
6,181,569
Members
453,053
Latest member
Kiranm13

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