Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Setting references to COM for locked code in Word 2002 VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
James - 28 Dec 2007 19:33 GMT
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!!
fumei - 28 Dec 2007 19:49 GMT
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.

>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
[quoted text clipped - 9 lines]
>startup folder, and how can I view the code when opened from the
>startup folder. TIA!!
James - 28 Dec 2007 20:05 GMT
> 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
[quoted text clipped - 42 lines]
> --
> Message posted via OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/200712/1

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?
Shauna Kelly - 28 Dec 2007 22:12 GMT
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

On Dec 28, 2:49 pm, "fumei via OfficeKB.com" <u37563@uwe> wrote:
> 1. "if the template is put into the startup folder and becomes, in
> effect,
[quoted text clipped - 58 lines]
> Message posted via
> OfficeKB.comhttp://www.officekb.com/Uwe/Forums.aspx/word-programming/200712/1

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?

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.