Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Preventing opening workbook inside active workbook.

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Preventing opening workbook inside active workbook.

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

-----Original Message-----
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

.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 599
Default Preventing opening workbook inside active workbook.

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.

--
Dick Kusleika
MVP - Excel
www.dicks-clicks.com
Post all replies to the newsgroup.

"Serge" wrote in message
...
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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
when opening an Excel Workbook, another blank workbook also opens Gord Dibben Excel Discussion (Misc queries) 0 October 12th 07 09:49 PM
when opening an Excel Workbook, another blank workbook also opens spmu Excel Discussion (Misc queries) 0 October 12th 07 01:46 PM
Active Cell when opening workbook mwclark0807 Excel Worksheet Functions 3 January 5th 06 04:38 AM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
Question for Experts: Opening workbook with workbook references Chris Excel Programming 0 September 11th 03 07:05 PM


All times are GMT +1. The time now is 02:47 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"