Debugging Windows Activate

John Davis

Well-known Member
Joined
Sep 11, 2007
Messages
3,457
Hello All:

I've been struggling with this one for a couple of hours. I have been trying to run a macro which was running fine this morning. However, now it stops at a line: Windows("ocean2").Activate. This file is open but the macro stops there and will not go any further. Any ideas on why this is happening??
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
John

Are you getting any error messages?

Can you post the rest of the code?
 
Upvote 0
Hi, John,

This morning your file was not saved yet. Now it is probably a "xls" file.
Add a DOT+extension to the filename.
Windows("ocean2.xls").Activate

You might consider to NOT activate nor select anything. Generally it is not needed to run code.

kind regards,
Erik
 
Upvote 0
Hi, John,

This morning your file was not saved yet. Now it is probably a "xls" file.
Add a DOT+extension to the filename.
Windows("ocean2.xls").Activate

You might consider to NOT activate nor select anything. Generally it is not needed to run code.

kind regards,
Erik


Thanks. You're absolutely right. I had figured it out, it's been a long day. If you have 4 workbooks open at the same time. How would you change focus, by not using activate?
 
Upvote 0
John

Well you wouldn't change 'focus' in the first place.

Try creating references to the relevant workbooks.

For example:
Code:
Set wb = Workbooks("ocean2.xls") ' create a reference using the workbook name
Code:
Set wbThis = ThisWorkboook ' create reference to workbook the code is in
Code:
Set wbAct  = ActiveWorkbook ' create reference to the active workbook
Code:
Set wbOpen = Workbooks.Open("C:\MyPath\MyBook.xls") ' open workbook and create a reference to it
Code:
Set wbNew = Workbooks.Add ' create new workbook and a reference to it
 
Upvote 0

Forum statistics

Threads
1,214,940
Messages
6,122,352
Members
449,080
Latest member
Armadillos

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