Copy Excel Data to a OneDrive Workbook Using VBA
Question details
Copy a range from a desktop Excel workbook to a shared workbook stored on OneDrive.

- 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.
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.
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.
Open the source workbook in desktop Excel. In OneDrive or Excel for the web, open the destination workbook and choose Open in Desktop App.
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
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.
In Excel, select Developer > Macros, choose CopyToOneDrive, and select Run. Check the destination workbook and confirm that OneDrive has finished syncing the saved changes.

Copy Table Rows Online with Power Automate
Use a cloud flow when the destination must remain online and your files are available to the Excel Online connector.
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.

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.




