problem with COM add-in

F

Frank Rice

Hi,
I have created a COM add-in for Word 2003 that also creates a
commandbar/commandbutton when the add-in is loaded in
IDTExtensibilty2_OnConnection.

I then delete and set the commandbar/commandbutton to Nothing in
IDTExtensibilty2_OnBeginShutdown.

However, when I reopen Word, I now have two commandbar/commandbuttons. I
think I remember that the commandbar/commandbutton is stored in Normal.dot.

Is this the problem? Is there anyway to get around this without deleting
Normal.dot?

Thanks

Frank
 
F

Frank Rice

As a followup to my own question, I did more research and came up with a
solution. As some of you probably know, many changes to Word are saved in
the Normal.dot. This includes the addition of commandbars/commandbarbuttons.
So what I ended up doing was:
On shutdown of Word, I deleted the commandbar/commandbarbutton and set their
references to Nothing.
Then I saved Normal.dot.
When reopened Word, the commandbar/commandbarbutton was added back in as I
wanted but there was only one copy on the toolbar. This is a good thing.

Frank.
 
S

Shauna Kelly

Hi Frank
many changes to Word are saved in the Normal.dot.
.... but only if you don't specify somewhere else.

May I suggest a different approach for your add-in?

If I were a user, and I used the add-in, then changes that I had made (eg
creating a temporary autotext, or recording a quick macro), and which I had
no intention of saving, would now have been saved by the add-in. And if I
were to find such an add-in, I wouldn't want to use it.

I think that control of the user's normal.dot should be left to the user.

A better solution may be to set the Application.CustomizationContext to
point to your own addin before making your changes, and then set the .Saved
state of the addin to true (so as not to befuddle the user with questions
asking if they would like to save the add-in).

This ensures that normal.dot is not touched, and not made dirty, by the
add-in.

Hope this helps.

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

Alex

Hello Shauna,

Shauna Kelly said:
A better solution may be to set the Application.CustomizationContext to
point to your own addin before making your changes, and then set the ..Saved
state of the addin to true (so as not to befuddle the user with questions
asking if they would like to save the add-in).

OK, I'm intrigued.

How do you set Application.CustomizationContext to point to a COM (IDTExtensibilty2) add-in?
I was under the impression that it can only point to a document or a template.


Best wishes,
Alex.
 
S

Shauna Kelly

Hi Alex

I think the typical approach is to create a .dot file, and have the COM
add-in load it as an Add-in at run-time. The .dot file can store toolbar
customizations, and the COM add-in can make any run-time changes to the
toolbars using the CustomizationContext to restrict the changes to the .dot
add-in, and prevent dirtying normal.dot.

Tom Winter explained the process well in his first post in this thread:
http://groups-beta.google.com/group..._frm/thread/e7fbedb1f538f64f/f129f36f61c89410

Hope this helps.

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


Hello Shauna,

Shauna Kelly said:
A better solution may be to set the Application.CustomizationContext to
point to your own addin before making your changes, and then set the
.Saved
state of the addin to true (so as not to befuddle the user with questions
asking if they would like to save the add-in).

OK, I'm intrigued.

How do you set Application.CustomizationContext to point to a COM
(IDTExtensibilty2) add-in?
I was under the impression that it can only point to a document or a
template.


Best wishes,
Alex.
 
A

Alex

Hello Shauna,

Shauna Kelly said:
Hi Alex

I think the typical approach is to create a .dot file, and have the COM
add-in load it as an Add-in at run-time. The .dot file can store toolbar
customizations, and the COM add-in can make any run-time changes to the
toolbars using the CustomizationContext to restrict the changes to the ..dot
add-in, and prevent dirtying normal.dot.

Tom Winter explained the process well in his first post in this thread:
http://groups-beta.google.com/group..._frm/thread/e7fbedb1f538f64f/f129f36f61c89410

Hope this helps.

Yes, it does.

Last question:
How do I create or load the custom template?


Best wishes,
Alex.
 
C

Charles Kenyon

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on moving / sharing / copying / backing-up customizations
including AutoText, AutoCorrect, keyboard assignments, toolbars, macros,
etc. This gives directions for creating the custom template. You will have
to determine where it will be stored during your installation and add code
to your COM add-in to load it. You are adding it to the templates collection
and will need its full name and path.


Hello Shauna,

Shauna Kelly said:
Hi Alex

I think the typical approach is to create a .dot file, and have the COM
add-in load it as an Add-in at run-time. The .dot file can store toolbar
customizations, and the COM add-in can make any run-time changes to the
toolbars using the CustomizationContext to restrict the changes to the
.dot
add-in, and prevent dirtying normal.dot.

Tom Winter explained the process well in his first post in this thread:
http://groups-beta.google.com/group..._frm/thread/e7fbedb1f538f64f/f129f36f61c89410

Hope this helps.

Yes, it does.

Last question:
How do I create or load the custom template?


Best wishes,
Alex.
 
A

Alex

Hell Charles,

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on moving / sharing / copying / backing-up customizations
including AutoText, AutoCorrect, keyboard assignments, toolbars, macros,
etc. This gives directions for creating the custom template. You will have
to determine where it will be stored during your installation and add code
to your COM add-in to load it. You are adding it to the templates collection
and will need its full name and path.

Thank you but this page talks about _manual_ operations.

I need to do everything programmatically.


Best wishes,
Alex.
 
C

Charles Kenyon

I've never created an active template programmatically, sorry. Are you sure
that you do need to do it that way? Can you not design a Word template and
distribute it with your COM add-in?
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.

Hell Charles,

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on moving / sharing / copying / backing-up customizations
including AutoText, AutoCorrect, keyboard assignments, toolbars, macros,
etc. This gives directions for creating the custom template. You will have
to determine where it will be stored during your installation and add code
to your COM add-in to load it. You are adding it to the templates
collection
and will need its full name and path.

Thank you but this page talks about _manual_ operations.

I need to do everything programmatically.


Best wishes,
Alex.
 
C

Charles Kenyon

What would be involved in creating such a template through code is to
(1) Create and name and save it. Documents.Add as a template
(2) Add it to the templates collection.
(3) Set it as your customization context.
(4) When your Add-In is shutting down, unload the new template and delete
it.

Or, at least that is what I think you would have to do, since I've never
done this.
--
Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://www.mvps.org/word which is awesome!
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
 
T

Tom Winter

Alex,

There are some downloads on my web site
(http://www.amosfivesix.com/downloads/ - see Word 97 COM Add-In Sample
Project) that show how to some of this stuff, though they include a lot of
other stuff you might not need. (Some day I create a nice simple demo of
this stuff - people keep asking for it!)

The first step is to create your basic .DOT add-in BY HAND at DESIGN TIME.
So you can do things manually to get things setup. That .DOT file that
you've setup with the basic default menu items, etc. is what you distribute
with your COM Add-in. Then when your COM add-in loads, you locate the .DOT
file. If you install the .DOT file in the same folder as your COM Add-in
DLL, you can just use App.Path (assuming VB6 here). Then call
Word.Application.AddIns.Add to load the add-in. You should then be able to
do:

Application.CustomizationContext =
Application.Templates("X:\FullPath\MyAddIn.dot") ' Again, you can use
App.Path the get the full path

Let me know if you need more details. I may well try to put together that
download sample today.

--
Tom Winter
(e-mail address removed)


Hell Charles,

See http://addbalance.com/word/movetotemplate.htm for step-by-step
instructions on moving / sharing / copying / backing-up customizations
including AutoText, AutoCorrect, keyboard assignments, toolbars, macros,
etc. This gives directions for creating the custom template. You will have
to determine where it will be stored during your installation and add code
to your COM add-in to load it. You are adding it to the templates
collection
and will need its full name and path.

Thank you but this page talks about _manual_ operations.

I need to do everything programmatically.


Best wishes,
Alex.
 

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