Setting active workbook value in Excel VBA

I now have my book set up in such a way where the workbook is hardcoded in the Set command, I wonder if there is a way to do this so that I can have it where it is fluid? Thus, no matter where this code is located (in another book), the code will adapt the new environment to it.

It makes sense?

Below I am now using what I would like to do, this is for ActiveWorkbookor something like this. Since this will be installed at the beginning of the code, not in the middle.

Set wbOOR = Application.Workbooks("Open Order Report.xlsm")

+5
source share
3 answers

You are probably after Set wbOOR = ThisWorkbook

Just clarify

ThisWorkbook will always refer to a book whose code is in

ActiveWorkbook will link to the active book

, . , , .

+20

,

Set wbOOR = ActiveWorkbook
+2

Try it.

Dim Workbk as workbook
Set Workbk = thisworkbook

Now everything that you program will only apply to your containing macroeconomic book.

0
source

All Articles