Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

calling macros between applications

Status
Not open for further replies.

smallcat

Technical User
Apr 8, 2001
3
US
I have macros in both Excel and Word/Excel mail merge, and I would like to open them from the same location. Is it possible?

Thanks
 
Hi!
In Excel Press Alt+F11 to Show The Visual Basic Editor.
Goto Tools>References and check microsoft word 9.0 object library.
Then Paste the following code into a new standard module:

Sub GetWord()
Dim MyWord As Word.Application ' Variable to hold reference
' to Microsoft Word.
Dim WordWasNotRunning As Boolean ' Flag for final release.

' Test to see if there is a copy of Microsoft Word already running.
On Error Resume Next ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
Set MyWord = GetObject(, "Word.Application")
If Err.Number <> 0 Then WordWasNotRunning = True
Err.Clear ' Clear Err object in case error occurred.


' Show Microsoft Word through its Application property.
MyWord.Application.Visible = True

' If this copy of Microsoft Word was not running when you
' started, create one using the CreateObject method.

If WordWasNotRunning = True Then
Set MyWord = CreateObject(&quot;Word.Application&quot;)
End If

MyWord.Run &quot;YourMacroName&quot;

Set MyWord = Nothing ' Release reference to the
' application and spreadsheet.
End Sub





smallcat wrote:

I have macros in both Excel and Word/Excel mail merge, and I would like to open them from the same location. Is it possible?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top