Understanding Workbooks.Worksheets vs. ActiveWorkbook.ActiveSheet

foolios

New Member
Joined
Aug 4, 2011
Messages
21
I can not get around why it is that I can't ever get the line or any similar lines such as:

Code:
Workbooks("InsertColumn").Worksheets("Sheet1").Columns(x).Insert

where the workbook name is InsertColumn,
to work with that specific Workbook. Or the problem might be that specific sheet. I'm not sure...

But if I use lines such as:

Code:
ActiveWorkbook.ActiveSheet.Columns(x).Insert

I dont' have an issue with that line other than I'm afraid that the line won't execute if the particular sheet isn't the one that's currently active.

Can someone please explain to me the difference? Is it a scope issue? What is the difference and why?

Thanks so much in advance.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
In the first piece of code you might be missing the extension for the workbook name.

When I try and refer to a workbook by name I have to include the extension, unless the workbook hasn't been saved yet.

I realise your reluctance to us ActiveWorkbook and it is possible you could refer to the wrong workbook.

That might be more likely to happen if you have other workbooks open, workbooks being opened/closed in the rest of the code etc.
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,862
Members
452,948
Latest member
UsmanAli786

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