Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Active workbook

Is there a way to tell if the workbook containing a macro
is the active workbook? I am calling a subrouting using
Application.OnTime (and calling itself in another interval
until it is stopped by using the Scheduled argument in
another OnTime call) but I would like it to do something
different if the workbook is not active. I know that the
macro continues to call itself if another workbook is
active or even if another application is active.

Thanks
JW
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Active workbook

Jack,

ActiveWorkbook always refers to the workbook that is active
regardless of whether it contains the running code. ThisWorkbook
always refers to the workbook that contains the code, regardless
of what workbook happens to be active. Therefore, you can simply
compare the Name properties to see if ThisWorkbook is the
ActiveWorkbook. E.g.,

If ActiveWorkbook.Name = ThisWorkbook.Name Then
' active workbook contains the running code
Else
' active workbook does not contain running code
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


"Jack Wolf" wrote in message
...
Is there a way to tell if the workbook containing a macro
is the active workbook? I am calling a subrouting using
Application.OnTime (and calling itself in another interval
until it is stopped by using the Scheduled argument in
another OnTime call) but I would like it to do something
different if the workbook is not active. I know that the
macro continues to call itself if another workbook is
active or even if another application is active.

Thanks
JW



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Active workbook

Chip-

Thanks for the response. The crucial question that I still
have is what happens when OnTime calls the procedure when
the user is working in another application. Will
ActiveWorkbook refer to the last workbook being used
before switching out of Excel or will it return null or
empty or something that will indicate that Excel does not
have the current focus?

Jack



-----Original Message-----
Jack,

ActiveWorkbook always refers to the workbook that is

active
regardless of whether it contains the running code.

ThisWorkbook
always refers to the workbook that contains the code,

regardless
of what workbook happens to be active. Therefore, you can

simply
compare the Name properties to see if ThisWorkbook is the
ActiveWorkbook. E.g.,

If ActiveWorkbook.Name = ThisWorkbook.Name Then
' active workbook contains the running code
Else
' active workbook does not contain running code
End If


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com


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
Active Workbook Kim Excel Discussion (Misc queries) 8 June 1st 10 11:33 PM
Store Active Workbook [email protected] Excel Discussion (Misc queries) 0 March 28th 07 03:30 PM
Active Workbook online. tamato43 Excel Discussion (Misc queries) 0 May 25th 05 04:38 PM
copy worksheet from closed workbook to active workbook using vba mango Excel Worksheet Functions 6 December 9th 04 07:55 AM
run a macro on an in-active workbook jfeka[_2_] Excel Programming 4 July 19th 03 03:49 PM


All times are GMT +1. The time now is 03:27 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"