Calling my AddIn on new documents

D

David Thielen

Hi all;

I have the hard part working - a VBA macro in my template calls my
AddIn and that all works great. Now a couple of final details.

Note - we need to do this on Office (Word, Excel, & PPT) 2000, 2002,
2003, & 2007.

1) I get the AddIn object by calling Set addIn =
Application.COMAddIns("AutoTag2007.Connect"). However our namespace
for the IDTExtensibility2 class is version dependent. So it could just
as well be AutoTag2003.Connect. Is there a way to find out if an AddIn
exists without throwing an exception?

2) I want to make our VBA code globally available to any document on a
user's system. Is there a way to do that or do they need to add it to
each document?

3) I need this to run when a new document is created (and it has our
macro). I don't care if it runs when an existing document is opened as
my AddIn handles that (checks to see that it has already done the
processing). I am using AutoOpen() in Word - is that the recomended
way?

3b) And what is it in Excel & PPT? Same thing?

4) I copied the .dotm file I created to C:\Documents and
Settings\david\Application Data\Microsoft\Templates and while it shows
up under new if I select "My templates..." it does not show up under
the default "Blank and recent" which is Blamk document and new blog
post. How can I get it added there?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
D

David Thielen

Problem with AutoOpen - if I have 1 document open and then create
another using my template - the macro is not called. Is there any way
to get that?

I can't do this on the new event because I need to prompt only if they
have my macro, not on all documents since many documents do not use
our system.

??? - thanks - dave


Hi all;

I have the hard part working - a VBA macro in my template calls my
AddIn and that all works great. Now a couple of final details.

Note - we need to do this on Office (Word, Excel, & PPT) 2000, 2002,
2003, & 2007.

1) I get the AddIn object by calling Set addIn =
Application.COMAddIns("AutoTag2007.Connect"). However our namespace
for the IDTExtensibility2 class is version dependent. So it could just
as well be AutoTag2003.Connect. Is there a way to find out if an AddIn
exists without throwing an exception?

2) I want to make our VBA code globally available to any document on a
user's system. Is there a way to do that or do they need to add it to
each document?

3) I need this to run when a new document is created (and it has our
macro). I don't care if it runs when an existing document is opened as
my AddIn handles that (checks to see that it has already done the
processing). I am using AutoOpen() in Word - is that the recomended
way?

3b) And what is it in Excel & PPT? Same thing?

4) I copied the .dotm file I created to C:\Documents and
Settings\david\Application Data\Microsoft\Templates and while it shows
up under new if I select "My templates..." it does not show up under
the default "Blank and recent" which is Blamk document and new blog
post. How can I get it added there?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
T

Tony Jollans

1) Sorry, I don't know (enough) to answer. In Word (VBA), all available
AddIns are in the Word.AddIns collection.

2) What VBA code? Code in your Template will be available to all Documents
based on it. To have code globally available, it needs to be in a global
template (in your Startup directory).

3) A new document does not have your macro. AutoOpen (and AutoNew) macros in
your Template are fine, although I prefer to use Document_Open and
Document_New events. But, if you want this globally you'll need to use
Application events in a global template.

4) If your template is neither blank nor recent, why should it show up
there? I think you could get it under "recent" by changing the registry, but
I'm not certain if that influences the current session.
 
J

Jie Wang [MSFT]

Hi David,

You can loop through the COMAddIns to find your AutoTag add-in:

Dim i As Integer

For i = 1 To Application.COMAddIns.Count
If Application.COMAddIns.Item(i).ProgId = "AutoTag2007.Connect" Or _
Application.COMAddIns.Item(i).ProgId = "AutoTag2003.Connect" Or _
Application.COMAddIns.Item(i).ProgId = "Whatever other versions you
have" Then
' Or If Left(Application.COMAddIns.Item(i).ProgId, 7) = "AutoTag" Then

....
End If
Next

For other questions, I need some time to find out.

By the way, could you let me know the reason why you want a globally
available macro while you already have an Add-In installed in Word?

Is there anything the Add-In can't do while the Macro can?

Thanks,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
D

David Thielen

...
By the way, could you let me know the reason why you want a globally
available macro while you already have an Add-In installed in Word?

Is there anything the Add-In can't do while the Macro can?

Hi;

Good question. Here's the fundamental problem I am trying to address.
Our system is used to design reports in Office (Word, Excel, & PPT).
So instead of using the SSRS designer in VisualStudio, you use Office.

When someone is creating a new report, we want to bring up a wizard to
get the template configured. But if they are creating a document that
is not a report template, then we do not want the wizard to come up.

What I thought would be the best way to do this is to have a
Word/Excel/PPT template with a macro that kicks off our wizard. And if
they have other Office templates that they want this to happen in,
they call the macro in them.

So, what do you think is the best way to accomplish this?

thanks - dave

david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
C

Cindy M.

Hi David,

I think (1) has been answered...
2) I want to make our VBA code globally available to any document on a
user's system. Is there a way to do that or do they need to add it to
each document?
The best approach is to load the templat containing the code as a
"global add-in". (Template add-in, not COM add-in - the list you see in
bottom of the "Templates and add-ins" dialog box.)

Your COM add-in can do this. Build on the code Jie has given you and, if
your add-in isn't found, use the Application.Addins.Add method to load
*and* install it (set that parameter to True). Adding it puts it in the
list in the dialog box. Setting Install to True activates that checkbox.
3) I need this to run when a new document is created (and it has our
macro). I don't care if it runs when an existing document is opened as
my AddIn handles that (checks to see that it has already done the
processing). I am using AutoOpen() in Word - is that the recomended
way?
You need what to run, exactly? The tools in an add-in template will be
globally available. And any commandbars should also be available
(assuming Visible = True).

Global templates don't trigger on Open or New events. You'd need to trap
the Application NewDocument event in your COM Add-in, then do something
(Application.Run if a VBA macro needs to run).
3b) And what is it in Excel & PPT? Same thing?
I haven't a clue :) They use a very different structure than Word.
4) I copied the .dotm file I created to C:\Documents and
Settings\david\Application Data\Microsoft\Templates and while it shows
up under new if I select "My templates..." it does not show up under
the default "Blank and recent" which is Blamk document and new blog
post. How can I get it added there?

I don't think this is the way you want to go. You could put it in the
profile's STARTUP folder, so that Word loads the template automatically
(instead of your add-in doing so). But personally, I think it's better
if your add-in takes care of loading/unloading. Then you can distribute
it to whatever location you like. (Caveat: Trust in Office 2007!)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi David,
When someone is creating a new report, we want to bring up a wizard to
get the template configured. But if they are creating a document that
is not a report template, then we do not want the wizard to come up.

What I thought would be the best way to do this is to have a
Word/Excel/PPT template with a macro that kicks off our wizard. And if
they have other Office templates that they want this to happen in,
they call the macro in them.

So, what do you think is the best way to accomplish this?

I'm not quite clear on the proposed user work-flow, here. Let me double
-check my understanding...

The person creating the base-document (I'm deliberately avoiding the
term "template", as for me that's something very specific in the Word
object model) for the reports. He's sitting in the Office (Word)
application and says to himself, "OK, let's create that report thing."

At this point, he's probably looking at the default empty Word document,
or he's just finished doing something else. But the assumption is that
he's going to start fresh at this point.

So... He clicks a button in a commandbar or Ribbon to start the process?
And wouldn't that start the Wizard - from within your COM Add-in?

I don't quite follow the logic of why you need VBA macros, too?

(When I started reading this message thread, I thought you might be
exposing the programming interface to VBA devs, as well...)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
D

David Thielen

Hi David,


I'm not quite clear on the proposed user work-flow, here. Let me double
-check my understanding...

The person creating the base-document (I'm deliberately avoiding the
term "template", as for me that's something very specific in the Word
object model) for the reports. He's sitting in the Office (Word)
application and says to himself, "OK, let's create that report thing."

At this point, he's probably looking at the default empty Word document,
or he's just finished doing something else. But the assumption is that
he's going to start fresh at this point.

So... He clicks a button in a commandbar or Ribbon to start the process?
And wouldn't that start the Wizard - from within your COM Add-in?

That was my proposal. But the marketing group here wants it that the
select a template from the New menu that is titled "Report Template"
and that then causes the wizard to run when the document is first
opened.

With that said, if it is not possible to do this, a wizard menu item
is our backup.

thanks - dave


david@[email protected]
Windward Reports -- http://www.WindwardReports.com
me -- http://dave.thielen.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
J

Jie Wang [MSFT]

Hi David,

So is it possible for you add-in to monitor the Application.NewDocument
event, and within that event the add-in code determines whether the new
document is based on your "Report Template"?

If this is acceptable, we can take a look at how to implement it.

Thanks,

Jie Wang

Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 2 business days is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions. Issues of this
nature are best handled working with a dedicated Microsoft Support Engineer
by contacting Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

Cindy M.

Hi David,
But the marketing group here wants it that the
select a template from the New menu that is titled "Report Template"
and that then causes the wizard to run when the document is first
opened.

I agree with Jie Wang. I'd have your NewDocument event look at the
AttachedTemplate property of the document and, if it's "good", make
the features visible/available.

Of course, you'd also want to implement the other events if the user
switches between documents.

Barring that, you'd put VBA code in the template, yes. A macro named
AutoNew or the "New" event from within the ThisDocument module will
execute when a new document is generated (but not when the template is
opened).

(Usually, it's immaterial which you decide to use. One executes after
the other, but I haven't memorized which order. Shouldn't matter for
this scenario.)

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
D

David Thielen

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