Activate a workbook on OneDrive

tucsondonpepe

New Member
Joined
Jan 30, 2022
Messages
43
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Good afternoon,

I want to activate an Excel file that resides on OneDrive. This code opens the file.

Sub Copy_Data_From_Excel_File_On_OneDrive()

Set objLogExcel = CreateObject("Excel.Application")
objLogExcel.Visible = True

Set wkbStockTransTable = objLogExcel.Workbooks.Open _
(FileName:="Sign in to your Microsoft account")

Workbooks("9-2022 Summer Season Games Won (A).xlsx").Activate

Sheets("Sheet1").Select
Range("A1").Select

Columns("A:I").Copy

Sheets("Sheet2").Select
With ActiveSheet.Columns("A:I")
.PasteSpecial xlPasteValues
.PasteSpecial xlPasteFormats
End With

End Sub

The Set .... is being changed when I post this. This is what it looks like

1658509834273.png

The file opens but the "Workbooks("9-2022 Summer Season Games Won (A).xlsx").Activate" line produces the Run-time error '9': subscript out of range.
 
Last edited:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
The name of the workbook seems to be "9-2022 Summer Season^GGames Won (A).xlsx"; but you can refer it as wkbStockTransTable, don't forgetting targetting the new Excel session
Thus, for example:
VBA Code:
objLogExcel.Workbooks("9-2022 Summer Season^GGames Won (A).xlsx").Activate

VBA Code:
objLogExcel.wkbStockTransTable.Activate

VBA Code:
objLogExcel.wkbStockTransTable.Sheets(1).Range("A1:B1")
 
Upvote 0
Anthony,

Thank you for the information. I will be testing it in my macros soon.

Can you provide a link so I can study how to interact with the OneDrive?

Thanks.

Joe
 
Upvote 0
Can you provide a link so I can study how to interact with the OneDrive?
I'm sorry, but don't have any suggestion for you (and indeed the code I suggested is not peculiar to OneDrive)
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,203
Members
452,617
Latest member
Narendra Babu D

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