Preventing opening workbook inside active workbook.

  • Thread starter Thread starter Serge
  • Start date Start date
S

Serge

I have a workbook with running macros and being
inexperienced in VBA I often used ActiveWorkbook to refer
to that workbook in macro code.
For example, inside Worksheet_Calculate() event I use
ActiveWorkbook.Worksheets("X").range("A1") = time()

The problem with Activeworkbook is that when I double
click on any Excel file to open, it opens inside my
workbook with macros and now ActiveWorkbook becomes this
new workbook, which causes the error since new workbook
doesn't have sheet X, but even if it did I dont want to
display time on new workbook.

Anyways, I want macro workbook to prevent having new
workbooks open inside it's excel app instance.

Hope it's not too wordy for simple problem.

Serge
 
try ThisWorkbook instead if you want to limit your macro
to the macro-storing workbook.
Good luck,
Luda
 
Serge

I don't know of a way to do that, but you should adjust your code instead of
trying to control the environment. You should use

ThisWorkbook - refers to the workbook that holds the code regardless if it's
active.

or

Me.Parent - when you're in the sheet's class module, the Me keyword refers
to the sheet. The Parent property will return the workbook.
 
Back
Top