VBA to save to OneDrive

Shales

Board Regular
Joined
Aug 8, 2006
Messages
171
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have a Macro spreadsheet which I am trying to share with other users via OneDrive.

Sharing the Spreadsheet is no problem but the other users cannot use my macro to export to OneDrive because they do not have access to the "my" username file path;

Code:
Sheets("Export").Select
    Sheets("Export").Copy
     Sheets("Export").Range("T2").Value = counter
    ActiveWorkbook.SaveAs Filename:= _
        "C:\Users\ME\OneDrive - COMPANY\test\" & Format(Now(), "USER" & "ddmmyy") & "Batch" & counter & ".xlsx", FileFormat:= _
        xlOpenXMLWorkbook, CreateBackup:=False[\CODE]

Is there a way around this? I am open to potential workarounds as long as it's VBA. I can't simply create a dropbox solution, or anything like that.

Thank you,
Gav
 
Sorry for the path error. I didn't do a file save otherwise I'd have noticed
You sorted it though and that's a better outcome.
 
Upvote 0

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
If you have a folder sync to your computer and you share that folder to other users, if you change anything in your file, they will see the updated file, goes the same the other way around, if they modify anything on any of your shared files or folders you will see them updated.

I have for example a folder from a co-worker synced to my computer... the path goes like this:

C:\Users\MyUser\MyCompany\Co-workers-Name - Folder name

So if I edit any file with vba,
 
Upvote 0
I know this is an ANCIENT thread ... but I was beating my head on this one and stumbled across a solution that worked for me:
the answer is to use CurDir to get the "local" OneDrive path, rather than ActiveWorkbook.Path or ActiveWorkbook.FullName
CurDir is an Office VBA function, rather than Excel VBA but it works.
Info on CurDir and related functions: CurDir function (Visual Basic for Applications)
 
Upvote 1
I know this is an ANCIENT thread ... but I was beating my head on this one and stumbled across a solution that worked for me:
the answer is to use CurDir to get the "local" OneDrive path, rather than ActiveWorkbook.Path or ActiveWorkbook.FullName
CurDir is an Office VBA function, rather than Excel VBA but it works.
Info on CurDir and related functions: CurDir function (Visual Basic for Applications)
Ancient but saved my bacon!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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