How to Reference a Local OneDrive Folder in Excel VBA
Question details
The user needs to reference a local synchronized OneDrive folder in Excel VBA so that file open and SaveAs operations use a valid local path instead of a OneDrive web sharing URL.

- Product
- WPS Office Spreadsheets (Excel VBA)
- Device & OS
- not provided
- Scenario
- The user is writing or updating an Excel VBA macro that opens or saves files stored in OneDrive.
- Observed behavior
- The macro cannot reliably use a OneDrive web sharing URL as a file path; it needs the local synchronized folder path, for example C:\Users\YourUsername\OneDrive\FolderPath\.
Before editing the VBA code, confirm the OneDrive desktop app is installed, the target folder is synchronized to the local computer, and the files are available offline so the local path resolves correctly.
Use the local synchronized OneDrive path in your VBA code
Use this when your Excel VBA macro needs to open or save files stored in OneDrive and should not rely on a web sharing URL.
OneDrive provides both a web sharing URL and a local synchronized folder path. Excel VBA file commands such as Workbooks.Open and ActiveWorkbook.SaveAs require a valid local file system path, so the local OneDrive folder is the correct reference.
Press Windows + E to open File Explorer, expand your OneDrive folder, and navigate to the synchronized subfolder that your VBA macro will use.
Click the File Explorer address bar to reveal the full local path, for example C:\Users\YourUsername\OneDrive\FolderPath\, and copy it. You can also right-click the folder, choose Properties, and check the Location field.
In the VBA editor, set the folder location to the local path: Location = "C:\Users\YourUsername\OneDrive\FolderPath\". Replace YourUsername and FolderPath with the actual values from your computer.
For saving, call ActiveWorkbook.SaveAs Filename:=Location & "report.xlsx", FileFormat:=xlOpenXMLWorkbook. For opening, call Workbooks.Open Filename:=Location & "report.xlsx".

Reference Your Local OneDrive Folder in WPS Office VBA
WPS Office Spreadsheets supports Excel VBA macros and can use the local synchronized OneDrive folder path, so you can open, edit, and save .xlsx or .xlsm files without relying on web sharing URLs.
- 1. Open the VBA editor in WPS Spreadsheets: In WPS Office Spreadsheets, open the workbook and press Alt+F11, or click the Developer tab and select Visual Basic to open the VBA editor.
- 2. Replace web URLs with the local OneDrive path: In your macro, assign the local synchronized path to a variable: Location = "C:\Users\YourUsername\OneDrive\FolderPath\". Do not use the OneDrive web sharing URL for file operations.
- 3. Use the correct Excel file format for SaveAs: Call ActiveWorkbook.SaveAs Filename:=Location & "report.xlsx", FileFormat:=xlOpenXMLWorkbook for .xlsx files, or use FileFormat:=xlOpenXMLWorkbookMacroEnabled for .xlsm macro workbooks.
- 4. Run the macro and verify OneDrive sync: Run the macro from the Developer tab or press F5 in the VBA editor, then confirm the file appears in the local OneDrive folder and that OneDrive sync uploads it.

Frequently Asked Questions
Can Excel VBA open a OneDrive file using a web sharing URL?
No. A OneDrive web sharing URL is not a normal file path. Use the local synchronized path, for example C:\Users\YourUsername\OneDrive\FolderPath\, so Workbooks.Open and SaveAs can access the file normally.
Where can I find my local OneDrive folder path?
Open File Explorer, select your OneDrive folder, and click the address bar to copy the full local path. You can also right-click the folder, choose Properties, and view the Location field.
Do I need to change msoFileDialogFolderPicker for OneDrive?
No. msoFileDialogFolderPicker already returns the selected local path. Simply select the synchronized OneDrive folder in the dialog and use that returned local path in your macro.
Why does my VBA macro fail after moving files to OneDrive?
The macro likely still uses an old local path or a web URL. Update it to the current local synchronized OneDrive folder path, and make sure the files are available offline before the macro runs.
How do I save an Excel workbook to a local OneDrive folder with VBA?
Use the local OneDrive path as the Filename argument: ActiveWorkbook.SaveAs Filename:=Location & "filename.xlsx", FileFormat:=xlOpenXMLWorkbook, where Location is the local synchronized folder path.




