Easy Question. What code will open up a MS Word document while in Excel?


Posted by James Hill on September 28, 2001 1:25 PM

In my workbook, I have a message box pop up asking the user whether or not they have read over the help file instructions for my program. What code can I insert into the function that will launch the external MS Word document that I have created. I haven't yet figured out where the word file will be saved, but I imagine I can just plug that into the path later on. Related to this issue, is there any way for excel to search the entire hard drive and/or the CD-Rom drive for this help file? I appreciate any suggestions for handling this issue.

Posted by Russell Hauf on September 28, 2001 2:43 PM

Try something like this:

Sub SearchForAndOpenWord() ' wow, what a long function name!

Dim objWord as Word.Application
Dim strWordDoc as String


With Application.FileSearch
.NewSearch
.FileName = "MyFile.doc"
.LookIn = "C:\"
.SearchSubFolders = False
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
.Execute > 0 Then
If .FoundFiles.Count > 0 Then
strWordDoc = .FoundFiles(1)
Else
msgbox "File not found"
Exit Sub
End If

End With

On Error Resume Next

Set objWord = GetObject("Word.Application")
If Err.Number <> 0 Then
Err.Clear
Set objWord = New Word.Application
End If

objWord.Documents.Open strWordDoc

' etc.

End Sub

Have fun - I hope this helps,

Russell

Posted by Russell Hauf on September 28, 2001 2:45 PM

Oops - change .SearchSubFolders to TRUE (nt)

Posted by Ivan F Moala on September 28, 2001 4:08 PM

Re: Oops - change .SearchSubFolders to TRUE (nt)

You also need to reference the
microsoft word object library

Ivan

Posted by Russell Hauf on September 28, 2001 6:16 PM

Re: Oops - change .SearchSubFolders to TRUE

Thanks Ivan, I thought about saying that while I was writing the code and forgot. Nice catch!

Russell You also need to reference the



Posted by James Hill on October 01, 2001 1:39 PM

I get an error message when running this

Thanks for the responses guys. Unfortunately Excel wouldn't accept of the lines of code. It was the line that read:

.Execute > 0 Then


Excel said that there was a compile error: syntax error when I tried to run it. Any other suggestions for fixing it. I am very new to this stuff.