How to define this workbook and active workbook

amkumar

New Member
Joined
Apr 5, 2016
Messages
45
Hello,

i need some coding in VBA which can define this workbook & active workbook in any example.


Thanks
Amit
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
In that case you need to explain to us what you actually want to know !
 
Upvote 0
Amit

You don't need to define ThisWorkbook and ActiveWorkbook, they already exist.

ThisWorkbook refers to the workbook the code is in and ActiveWorkbook refers to the currently active workbook.
 
Upvote 0
Unless, of course you need....
Code:
dim Wb as workbook
Set Wb=Thisworkbook
OR
Set Wb=activeworkbook
 
Upvote 0
An example:


Code:
Sub test()
    Dim wb1 As Workbook, wb2 As Workbook
    Workbooks.Open "file1.xlsx"
    Set wb1 = ActiveWorkbook    'The wb1 object is established in the active book (it is the recently opened book)
    
    Set wb2 = ThisWorkbook      'It does not matter which book is active, in the object wb2 the book that contains this macro is established.
    
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,161
Members
453,021
Latest member
Justyna P

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