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
Ivan
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
Err.Clear
GoTo OpenWordandDoc
Esle
GetObject(C:\TestFile.Doc)
End If
This Microsoft so called "Help" is driving me mad. Do you know of a good Visual Basic book?
Thanks
Michele
MICHELE
EMAIL me and I'll send you some VBA help files
Ivan
Dear Ivan,
I don't know your e-mail.
I include mine (see above)
Thanks
Michele
Hello Ivan,
It seems my e-mail address doesn't get transmitted so here it is:
michaelpettinicchi@hotmail.com
Thanks,
Michele