Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Working with a template - referencing and activating

Using Office 2003 and Windows XP;

I am opening a file as a template (Workbooks.Add) to keep users from
damaging a form that is opened from a button on a toolbar.

However, because the template is unsaved, it's a bit harder to work with.
For example: Workbooks("TemplateName").Activate
The above didn't work for me to switch back and forth between files.

Is there another way to reference an unsaved template file so I can activate
it when needed?

Just personal preference, but I'd rather not use an object reference when it
is added, however, I will if it is necessary...if this is the only way, could
someone please post example code on how to get the object reference? --- and
then, does the object reference stay available even though the file loses
focus?

Thanks much in advance.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Working with a template - referencing and activating

Use code something like

Sub AAA()
Dim WB As Workbook
Set WB = Workbooks.Open(Filename:="C:\MyTemplate.xlt")
End Sub

Then you can do anything you want with the WB object within the sub AAA.
Because WB is declared within the AAA procedure, it will be destroyed when
the procedure ends. If you declare it as a Public variable, before and
outside of any procedure, it will remain accessible until the workbook in
which it is defined is closed. A Public variable is accessible in any
procedure in any module of the VBA Project.

Public WB As Workbook

Sub AAA()
Set WB = Workbooks.Open(filename:="C:\MyTemplate.xlt")
End Sub

Sub BBB()
MsgBox WB.Name
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"XP" wrote in message
...
Using Office 2003 and Windows XP;

I am opening a file as a template (Workbooks.Add) to keep users from
damaging a form that is opened from a button on a toolbar.

However, because the template is unsaved, it's a bit harder to work with.
For example: Workbooks("TemplateName").Activate
The above didn't work for me to switch back and forth between files.

Is there another way to reference an unsaved template file so I can
activate
it when needed?

Just personal preference, but I'd rather not use an object reference when
it
is added, however, I will if it is necessary...if this is the only way,
could
someone please post example code on how to get the object reference? ---
and
then, does the object reference stay available even though the file loses
focus?

Thanks much in advance.


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
INDIRECT not working as expected - referencing multiple dynamicranges Paul Martin[_2_] Excel Discussion (Misc queries) 0 January 28th 10 12:45 AM
Remove the Task Pane when working in a template JCzech Excel Discussion (Misc queries) 0 September 15th 07 03:16 PM
Working within a workbook without activating it? hyyfte[_11_] Excel Programming 3 June 4th 06 08:00 PM
Activating/De-activating buttons Nash Excel Programming 4 June 22nd 05 07:24 AM
Working within a workbook without activating it? hyyfte[_9_] Excel Programming 1 September 20th 04 03:34 PM


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