Running a macro from another document.

K

Ken Valenti

I want to distribute code that will work on any document in Word 2003.

This code will add a new command bar with one button.

Sub AddToolBar()
Dim Mybar As CommandBar
Set Mybar = CommandBars.Add(Name:="Test Menu", Position:=msoBarFloating,
temporary:=True)
Mybar.Visible = True
With Mybar.Controls.Add
..Style = msoButtonCaption
..Caption = "Test Macro"
..OnAction = ThisDocument.Name & "!RunThisMacro"
End With
End Sub


The button will run the macro fine, but only on the docuement containing the
macro.
The macro won't run when a different docuement is active

Since I need to distribute this to other people, I don't want to modify the
normal.dot.

Do I need to create an addp-in or ???
 
K

Ken Valenti

Thank you, but I didn't really like the answer.
None of my users would know how to do this and I don't like dealing with IT.

I was able to solve my problem with this code.

Sub ManipulateOpenDocuments()
Dim TestDocument As Document
For Each TestDocument In Application.Documents
If TestDocument.Name <> ThisDocument.Name Then
TestDocument.Activate
Application.Run ("TheMacroName")
End If
Next
End Sub

It's run from a button on the document with the macros (that I use as
instructions) and works on all open documents.

This allows me to just maintain one file and email or send out a link to my
product without the user having to do anything..

Thanks again,

Ken
 
J

Jay Freedman

To each his own... I hope your instructions include a section on how to set the
macro security level low enough that the macros can run. That isn't something
you can manipulate programmatically.
 

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