Toolbar for non-COM add-in

S

Sam Hobbs

I have a VBA macro I am trying to use as an add-in. I understand or can
understand everything except the documentation is not clear about creating a
toolbar for the add-in. I am developing the add-in for installation in other
systems; if it were for personal use then I could just create a toolbar
manually.

I don't know how things are supposed to work. I assume that the toolbar
could be and should be created when the add-in is added using the add-in
manager, but that is what the documentation is not clear about. I used the
Word 2000 documentation; if the documentation for later versions of Word
does explain all this, then I apologize for not looking at it. I did however
search the MSDN using:

http://search.msdn.microsoft.com/De...rand=msdn&locale=en-us&refinement=&lang=en-us

I am interested in reading the documentation and/or other articles if I can
find them.

I mainly need to know if there is a mechanism for adding or deleting a
toolbar for a non-COM add-in when it is added or deleted; if there is not,
then knowing it does not exist will save time searching for something that
does not exist.
 
D

Doug Robbins - Word MVP

See the following articles:

"How to assign a Word command or macro to a toolbar or menu" at:

http://www.word.mvps.org/FAQs/Customization/AsgnCmdOrMacroToToolbar.htm

"Assigning custom button images to your toolbar and menu buttons" at:

http://www.word.mvps.org/FAQs/Customization/CustomButtonImages.htm

"How to use VBA to set a custom graphic on a toolbar button" at:

http://www.word.mvps.org/FAQs/MacrosVBA/SetCustomButtonImage.htm

"How do I find out or change programmatically which macro is attached to a
button on my toolbar?" at:

http://www.word.mvps.org/FAQs/MacrosVBA/AttachMacroToButton.htm


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sam Hobbs

Thank you.

The "How to assign a Word command or macro to a toolbar or menu" article
appears to describe the procedure for doing it "manually", as in a person
doing it using the Word UI directly. Does it describe how to assign a macro
to a toolbar without using any macro code to do it? If that is what it does,
then is there some other term I should use beside "manual" to communicate
that? I agree that "manual" is not the best term but it is the one I hear
others using for things such as that and it has been used like that for more
than a quarter of a century.

I don't see any mention in any of the other three artciles about add-ins;
did I miss something?
 
D

Doug Robbins - Word MVP

I think we need to back up a bit. The statement that "I have a VBA macro
that I want to use as an addin" is not the way things work. If you have a
macro that you want to make available to all documents, then the macro needs
to be created in a template that you save in the Word Startup folder. That
template is what then becomes an Add-in and any macros or toolbars that are
created in that template will then be available to all documents. When you
create the toolbar in the template, which is covered in the article "How to
assign a Word command or macro to a toolbar or menu", that toolbar will
appear when Word starts.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
S

Sam Hobbs

I understand that "the macro needs to be created in a template that you save
in the Word Startup folder". No problem there.

When you say "any macros or toolbars that are created in that template will
then be available to all documents", I think that is the part that I did not
get. It is probably very obvious to you and the Microsoft people but
eventhough the answer is that simple (if it is the answer to my question)
then it was totally absent from my understanding. It is likely a missing
link that Microsoft can easily include in the documentation but it is often
rare for technical writers to be able to think from the point of view of the
reader.
 
D

Doug Robbins - Word MVP

Do you still have a question or have you been able to do what you wanted?

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
F

fumei via OfficeKB.com

I think we need to clarify "non-COM addin".

What makes you think it is a non-COM addin?

The point (at least regarding Word) is that a .dot file (a template file)
that is being used a code container - i.e. a GLOBAL template - is, by its own
existence considered an add-in. Placed in the Startup folder, it acts like
an add-in. Its procedures are available globally, that is, in any document.

ANY template (.dot file) can be loaded as a add-in via Tools > Templates and
Add-ins. It can be loaded manually (clicking Tools > Templates and Add-ins >
Add...etc. etc), or via code.

If it is NOT already listed as an available Add-in

AddIns.Add FileName:="C:\Templates\Whatever\Yadda.dot", Install:=True

If it IS already listed, but NOT installed (loaded)

AddIns("Yadda.dot").Installed = True

While most people often store procedures in a global template in Startup,
there are some advantages to loading and UNLOADING code containers (.dot
files). You unload simply by making Installed = False.

AddIns("Yadda.dot").Installed = False

A .dot file in Startup is automatically loaded as a add-in.

There, that is all there is to it. If you have a VBA procedure, and you save
the file containing the project (containing the procedure) as a .dot file,
and you put that file in the StartUp folder....voila, it IS an automatically
loaded add-in, and the procedure is available to any document.

""any macros or toolbars that are created in that template will
then be available to all documents", I think that is the part that I did not
get."

It means exactly that. Any macros (procedures) or toolbars in a template (.
dot file) in Startup is available to all documents.

Sam said:
I understand that "the macro needs to be created in a template that you save
in the Word Startup folder". No problem there.

When you say "any macros or toolbars that are created in that template will
then be available to all documents", I think that is the part that I did not
get. It is probably very obvious to you and the Microsoft people but
eventhough the answer is that simple (if it is the answer to my question)
then it was totally absent from my understanding. It is likely a missing
link that Microsoft can easily include in the documentation but it is often
rare for technical writers to be able to think from the point of view of the
reader.
I think we need to back up a bit. The statement that "I have a VBA macro
that I want to use as an addin" is not the way things work. If you have a
[quoted text clipped - 61 lines]
 
S

Sam Hobbs

Is it ever possible for a VBA macro to be a COM object? Is that possible?

If it is possible, then I was not as clear as I could have been. If however
it is not possible for a macro to be a COM object then what makes you think
that a macro could be a COM add-in?
 
S

Sam Hobbs

Do you see a question?

Thank you for your interest; I will let you know if it works when I get a
chance to get back to this.

I don't know if it will do what I need to do. If I had asked the question
just in time to get answer then when I needed an answer I would have gotten
the answer too late. I asked the question when I had time to wait. I have
not yet gotten back to this.
 
S

Sam Hobbs

I assume it will work, but there is a problem that is not really related to
my question. I created the toolbar but when I click it I get a message
saying "The macro cannot be found or has been disabled because of your Macro
security settings.".

I will leave this for the developer of the system that the macro is a part
of; if it is security and the solution is signing, then he must arrange for
that, I cannot. I won't be doing the installation part and such.
 
F

fumei via OfficeKB.com

You are correct. A "macro" itself is never a COM object. A macro is simply
a procedure. Period.

Again, if your toolbar (or whatever) is in a .dot file, and that .dot file is
loaded as an Add-in (global by being in Startup) then toolbars, procedures
(macros) will be available to all documents automatically.

Or, again, you can load it dynamically.

Forget about COM, it has nothing to do with what you seem to be asking.

If your VBA procedures are compiled into a DLL (using VB6 for example), then
once the DLL is registered, the procedures will also be available. However,
again, this does not appear to be what you are asking about.

If I understand correctly, you want your toolbars etc available. You can do
that, as it has been explained to you.
 
S

Sam Hobbs

Thank you; I think you understand.

Yes, I did get as far as creating a document template in the startup folder.
Yes, COM is essentially not relevant. Also, there is no DLL for this either.

This VBA macro just loads a XML file and then executes VBScript regular
expressions (RegExp objects) for each sentence in a document. I could have
been more specific about what the macro does but my experience is that
irrelevant details such as those just cause irrelevant discussion. I hope I
did provide a reasonable description of what I was trying to ask.
 

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