MrExcel Publishing
Your One Stop for Excel Tips & Solutions

Start/Activate File In Other Application

Posted by Michele on May 23, 2001 2:05 AM

1) The Microsoft Help says I can use:
AppActivate "title in title bar of the application"
e.g., AppActivate "Microsoft Word"
However, this doesn't work. What am I doing wrong?

2) How do I start/activate, from an Excel workbook program, a file in another application. e.g., from my Excel program I want to start/activate existing file "C:\TEST.DOC" in Microsoft Word application? I used to be able to do this very easily in Lotus.

Many thanks!

Posted by Ivan Moala on May 23, 2001 6:05 AM

1) For word97 the Title = "Microsoft Word"
word2000 the Title = the documant name THEN
"Microsoft word"
The AppActivate Title is similar to the
API call Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
ie. it searchs for the Windows Title.

2) you can either do this from code or simply
hyperlink the document.
Insert / Hyperlink / select browse and then
your file

By code;
'From Msoft
'Opening a Microsoft Word Document

'This example demonstrates how to use Automation to open Microsoft Word
'and a document for viewing.
'Note the use of the Static keyword to prevent the object variable from losing scope.
'Once the object variable loses scope, the instance of Microsoft Word is destroyed.

Sub OpenWordDoc()
Static WordObj As Word.Application
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open ("C:\My Documents\test.doc")

'Enable viewing the Word session and its document
WordObj.Visible = True
End Sub

Note you will need to reference the Object Library
for the word version you are using eg
word97 = MSWORD8.olb
word2000 = MSWORD9.OLB


Posted by Michele on May 25, 2001 4:17 AM

Dear Ivan,

Many thanks for your help.

Unfortunately, it doesn't work if I use it as you stated. But if I do the following, it works.

Static WordObj
Set WordObj = Nothing
Set WordObj = CreateObject("Word.Application")
WordObj.Documents.Open ("C:\TestFile.DOC")

i.e., "Static WordObj As Word.Application" does not work. I get "User-defined type not defined."

One more thing if you can help.
Although it works with that one change, it always opens/starts a new copy of Word. I tried to test first if Word is running and if so open only the Word file but cannot get it to work. It just doesn't work like the Microsoft documentation or Help says. The code I used is:

Set MyApp = GetObject(, "Word.Application")
If Err.Number <> Then
GoTo OpenWordandDoc
End If

This Microsoft so called "Help" is driving me mad. Do you know of a good Visual Basic book?


Posted by Ivan Moala on May 25, 2001 4:47 AM

EMAIL me and I'll send you some VBA help files


Posted by Michele on May 28, 2001 3:03 AM

Dear Ivan,

I don't know your e-mail.

I include mine (see above)


Posted by Michele on May 28, 2001 3:07 AM

Hello Ivan,

It seems my e-mail address doesn't get transmitted so here it is: