vba help needed: Activate "original" window

ArchAngel

Board Regular
Joined
Apr 9, 2005
Messages
135
Hi All,

I have a macro which opens another workbook,
I want to then reactivate the original work book to enter in a vlookup formula.

I have managed to make it work, but it only works for a worksheet of a "fixed name"...

Is there a way to dynamically reactiveate the original worksheet?
or in other words, activate the worksheet the macro resides in?
(as the macro is to be imported into the spreadsheet in question).

Code:
Workbooks.Open Filename:="location\filename"
    Windows("fixed name").Activate
    Range("J2").Select
    Range("I2", Range("i" & Rows.Count).End(xlUp)).Offset(0, 1).Formula = "=VLOOKUP(RC[-9],filename!C3:C5,3,FALSE)"


Thanks very much!!!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Code:
ActiveWindow.ActivatePrevious

This seems to work, but I'm worried about it having a loophole somewhere...

anyone know?
 
Upvote 0
Hi

ThisWorkbook in VBA is an object reference to the workbook in which the code resides - so you can refer to it via:

Code:
ThisWorkbook.Activate

for instance.
 
Upvote 0

Forum statistics

Threads
1,214,648
Messages
6,120,726
Members
448,987
Latest member
marion_davis

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