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 sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Open a Microsoft Word file 1

Status
Not open for further replies.

GussyBoy

IS-IT--Management
Mar 11, 2003
96
BS
How do you instruct VB to open a Microsoft Word file? I see the wizard to open up MS Word but I'd like for it to open the file at the same time.

Please advise.
Thanks.
 
I wrote a FAQ about how to use mailmerge, and part of the code shows how to use late binding to open a word document no matter what version of Word they have installed (and yes, it would matter otherwise). See:

'Native' mailmerge reports - as painless as possible faq181-5088

The two line answer is:
Code:
Dim objWordDoc as Object
Dim strMergeDocumentFilename as String

Set objWordDoc = GetObject(strMergeDocumentFilename, "Word.Document")

--
Find common answers using Google Groups:

Corrupt MDBs FAQ
 
Try:

Application.FollowHyperlink "C:\Folder\Word.doc", , True

This will open the document (or any other file) in it's default program.

I use it for PDF's, Text files and even Access MDB's
 
Thanks. I'll give them both a try and let you guys know.
 
I like the hyperlink solution because its quite simple. I always use OLE with word because mail merge is horrible. The code below is quite long but is useful if you want to say launch a template and drive it from the software.

Note: if you are using a document then the DOCUMENTS.ADD needs to change.

The code will use the location of the database and know that a directory called letters exists.

Code:
-----
' NOTE: this requires a reference to the word 8.0 object library in TOOLS, REFERENCES
Dim objWord As Word.Document

' Store the path and name of the database
strName = CurrentDb.Name
' Shorten string to just the path
StrLength = Len(strName)
For LoopCounter = StrLength To 1 Step -1
If Mid(strName, LoopCounter, 1) = "\" Then
strName = Mid(strName, 1, LoopCounter)
Exit For
End If
Next LoopCounter


' Start Microsoft Word.
Set objWord = CreateObject("word.document")

With objWord.Application
' Make the application visible.
.Visible = True

' Maximise the window
.WindowState = wdWindowStateMaximize

' Create a new document from the template
.Documents.Add (strName + "\letters\letter.dot")

end with

release objWord
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top