Activate another workbook?

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
308
Office Version
  1. 365
Platform
  1. Windows
Apologies, I am having a brain freeze.

I am running a macro from a workbook (A) which opens another workbook (B) and then copies data from (B) to (A).

I have this
VBA Code:
Workbooks.Open filename:=folder & "\" & filename & ".xlsm", Notify:=False, ReadOnly:=True, Password:="lh01"
Range("Table1[[Contract No]:[Email Address]]").Select  ' falls over here with "select method of Range Class failed"

If I go into workbook (B) and manually select the sheet (which is named "contracts") and then continue with the code execution, it works fine.

What code do I need to make it work? Apparently this used to work fine up until recently (although I'm not sure why).

Thanks as always for any pointers.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Could be:

VBA Code:
  Workbooks.Open Filename:=folder & "\" & Filename & ".xlsm", Notify:=False, ReadOnly:=True, Password:="lh01"
  Sheets("contracts").Select
  Range("Table1[[Contract No]:[Email Address]]").Select  ' falls over here with "select method of Range Class failed"


But if you are going to copy, it is not necessary to select, just copy and then paste where you need it:

VBA Code:
  Workbooks.Open Filename:=folder & "\" & Filename & ".xlsm", Notify:=False, ReadOnly:=True, Password:="lh01"
  Sheets("contracts").Range("Table1[[Contract No]:[Email Address]]").Copy
  
  'For example:
  ThisWorkbook.Sheets("Sheet1").Range("A5").PasteSpecial xlPasteAll
 
Upvote 0
Solution

Forum statistics

Threads
1,226,113
Messages
6,189,048
Members
453,522
Latest member
Seeker2025

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