File Sharing Problems

Copy Excel Data to a OneDrive Workbook Using VBA

Tauseeq MagsiTauseeq Magsi Dec 2, 2026 868 views

Question details

Copy a range from a desktop Excel workbook to a shared workbook stored on OneDrive.

Copy Excel Data to a OneDrive Workbook Using VBA
Product
Microsoft Excel and Excel for the web
Device & OS
not provided
Scenario
The user wants to transfer data from a desktop workbook to a shared OneDrive workbook, preferably using VBA.
Observed behavior
VBA cannot reliably control an open Excel for the web workbook as it controls a desktop workbook.
Before you start

Confirm that you have edit access to the destination workbook and identify the source range and destination sheet. For the VBA method, open both workbooks in the same desktop Excel instance and enable macros only if you trust the code.

Solution 1Recommended

Open the OneDrive Workbook in Desktop Excel and Copy with VBA

Use this method when you can open the shared destination workbook in desktop Excel.

VBA controls the desktop workbook, not the browser tab. Changes saved to the OneDrive workbook can then sync for other users.

1
Open both workbooks

Open the source workbook in desktop Excel. In OneDrive or Excel for the web, open the destination workbook and choose Open in Desktop App.

2
Add the macro

In the source workbook, open Developer > Visual Basic, select Insert > Module, and add the following code: Sub CopyToOneDrive() ThisWorkbook.Worksheets("Sheet1").Range("A1:B10").Copy Destination:=Workbooks("Destination.xlsx").Worksheets("Sheet1").Range("A1") Workbooks("Destination.xlsx").Save End Sub

3
Update the references

In the module, replace Destination.xlsx, both Sheet1 references, A1:B10, and A1 with your actual workbook name, sheet names, source range, and destination cell.

4
Run and verify

In Excel, select Developer > Macros, choose CopyToOneDrive, and select Run. Check the destination workbook and confirm that OneDrive has finished syncing the saved changes.

Open the OneDrive Workbook in Desktop Excel and Copy with VBA
Opening a synced file by path: If the destination is synced locally, you can use Workbooks.Open with its local OneDrive path before copying. Avoid opening a second copy if the workbook is already open.
Free Microsoft Office alternative

Edit and Share Spreadsheet Data with WPS Office

WPS Office is a free, lightweight alternative for editing and sharing spreadsheets, with a familiar interface and Microsoft Excel format compatibility to help you move existing files. It does not provide the Microsoft Excel VBA control of Excel for the web described above.

Copy and edit spreadsheet ranges in WPS SpreadsheetsOpen and save Microsoft Excel XLSX filesWork in a familiar spreadsheet interfaceUse a free, lightweight Office alternative
microsoft office alternative - wps office

Frequently Asked Questions

Can VBA control a workbook that is open only in Excel for the web?

No. VBA cannot reliably automate the browser version as a desktop Excel workbook. Open the file with Open in Desktop App or use an online service such as Power Automate or Microsoft Graph.

How do I open a OneDrive workbook from VBA?

If OneDrive syncs the workbook to your computer, use Workbooks.Open with the local file path. Make sure you have edit access and avoid opening another copy if it is already open.

Will the VBA example copy formatting as well as values?

Yes. The Range.Copy method copies the range to the destination, including formatting. To transfer only values, assign the source range's Value to a destination range of the same size instead.

Why does the Power Automate method need tables?

The Excel Online (Business) actions List rows present in a table and Add a row into a table work with named Excel tables. Use Insert > Table in each workbook before configuring the flow.