Setting references to COM for locked code in Word 2002 VBA

J

James

I am trying to update a template which has code attached to it to
format, etc. I can open the template directly and get access to the
code, and I've made the changes. but they necessitate references to
the Outlook and Scripting libraries. However, if the template is put
into the startup folder and becomes, in effect, the normal.dot, I no
longer have access to the code (I go into macros, code, click on the
project and it says it is locked). So I don't think I can set the
references to the libraries necessary to get the template to run. I
checked the template on its own and the properties don't indicate that
it's locked or password-protected. So I guess there are 2 questions:
how can I make sure those references are in the code when run from the
startup folder, and how can I view the code when opened from the
startup folder. TIA!!
 
F

fumei via OfficeKB.com

1. "if the template is put into the startup folder and becomes, in effect,
the normal.dot" This is not correct at all. A template in Startup is a
global template. Technically, it does not affect normal.dot - although of
course it may contain code that does. Normal.dot is still, well, normal.dot.
Global templates are essentially code containers.

2. global templates are not "open" in the normal sense. Word parses the
code modules in a global and makes the procedures available, globally.
However, the file itself is NOT open. This is why the project is
"unviewable". The ONLY template that has viewable code modules while the
file is unopened, is normal.dot. ALL other template/document code modules
must have the file itself open in order to view/modify code.

So to answer your two questions:

a) "how can I make sure those references are in the code" - by putting the
References into the template. References are not really "in" the code. The
project has references. So...put the references in. I am not quite
following what the problem is.

b) "and how can I view the code when opened from the startup folder" Again,
a Startup .dot file has its code modules accessible to execute, but the file
is NOT open. You must open the file itself to view/modify code.

My globals always have either a button, or a keyboard shortcut, that opens
the file itself. I do this for easy access to it so I can, in fact, modify
code.

Note: modified code in a global is immediately accessible as such.
 
J

James

1.  "if the template is put into the startup folder and becomes, in effect,
the normal.dot"  This is not correct at all.  A template in Startup isa
global template.  Technically, it does not affect normal.dot - although of
course it may contain code that does.  Normal.dot is still, well, normal..dot.
Global templates are essentially code containers.

2.  global templates are not "open" in the normal sense.  Word parses the
code modules in a global and makes the procedures available, globally.
However, the file itself is NOT open.  This is why the project is
"unviewable".  The ONLY template that has viewable code modules while the
file is unopened, is normal.dot.  ALL other template/document code modules
must have the file itself open in order to view/modify code.

So to answer your two questions:

a) "how can I make sure those references are in the code" - by putting the
References into the template.  References are not really "in" the code.  The
project has references.  So...put the references in.  I am not quite
following what the problem is.

b) "and how can I view the code when opened from the startup folder"  Again,
a Startup .dot file has its code modules accessible to execute, but the file
is NOT open.  You must open the file itself to view/modify code.

My globals always have either a button, or a keyboard shortcut, that opens
the file itself.  I do this for easy access to it so I can, in fact, modify
code.

Note:  modified code in a global is immediately accessible as such.

Regarding the references: when I code up the template it includes code
which uses Outlook and Scripting object libraries. Now, I am putting
these references in when I have the template open on its own, because
as you point out, I can't open it when it's in the startup folder.
Now, before I try to put this template into another user's startup
folder, I am curious whether those references I made earlier will
"stick". Does that clarify, I hope?
 
S

Shauna Kelly

Hi James

1. If you need to edit a global template (aka add-in), then unload it
first. That is, use Tools > Templates and Add-ins and un-tick the box.
Now, use File > Open to open it and work on it. Word will let you open
and edit a file that is simultaneously loaded as an add-in, but it is
not recommended--if Word is having a bad hair day, it can crash and
destroy the file. And to provide some certainty in case you open and
work on the file simultaneously by accident, make frequent backup
copies.

2. If your .dot file has references to a library, then the .dot file
will work on another machine if the other machine has the same library
and the same version of that library. If the other user has a later
version, then it will generally work, but you would need to test. If the
other machine does not have the library installed (eg in your case, the
other machine does not have Outlook installed), then the user will get
an unrecoverable error. You can't code around that error (ie you can't
do If ... Then; and you can't trap it with On Error ....). Instead, if
there is there is a chance that the other machine does not have the
required library, then use late binding.

For more info on that, see
Early vs. Late Binding
http://www.word.mvps.org/FAQs/InterDev/EarlyvsLateBinding.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word




1. "if the template is put into the startup folder and becomes, in
effect,
the normal.dot" This is not correct at all. A template in Startup is a
global template. Technically, it does not affect normal.dot - although
of
course it may contain code that does. Normal.dot is still, well,
normal.dot.
Global templates are essentially code containers.

2. global templates are not "open" in the normal sense. Word parses
the
code modules in a global and makes the procedures available, globally.
However, the file itself is NOT open. This is why the project is
"unviewable". The ONLY template that has viewable code modules while
the
file is unopened, is normal.dot. ALL other template/document code
modules
must have the file itself open in order to view/modify code.

So to answer your two questions:

a) "how can I make sure those references are in the code" - by putting
the
References into the template. References are not really "in" the code.
The
project has references. So...put the references in. I am not quite
following what the problem is.

b) "and how can I view the code when opened from the startup folder"
Again,
a Startup .dot file has its code modules accessible to execute, but
the file
is NOT open. You must open the file itself to view/modify code.

My globals always have either a button, or a keyboard shortcut, that
opens
the file itself. I do this for easy access to it so I can, in fact,
modify
code.

Note: modified code in a global is immediately accessible as such.

Regarding the references: when I code up the template it includes code
which uses Outlook and Scripting object libraries. Now, I am putting
these references in when I have the template open on its own, because
as you point out, I can't open it when it's in the startup folder.
Now, before I try to put this template into another user's startup
folder, I am curious whether those references I made earlier will
"stick". Does that clarify, I hope?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top