open word file, browse if not found

H

HeatherD

Hi! I'm hoping someone here can help me out with something that ha
been frustrating me for awhile...

I want to open a word document from excel (with a button) and if it i
not found i want the open file dialog box to appear for the user t
browse for the document in case it has been moved.

I have come up with the following code and it works well except i
opens two instances of word if the file is not found. if the file i
found, there are no problems. Does anyone know how to fix the code s
that only one instance of excel will be open??



Sub OpenWord()
MyDoc = "C:\Documents and Settings\dickisoh\Desktop\Work\CAA Yea
Change Instructions"
On Error GoTo C:
Set WdApp = CreateObject("Word.Application")
WdApp.Visible = True
WdApp.Documents.Open MyDoc
Set WdApp = Nothing
Exit Sub
C: Msg = MsgBox("The CAA Year Change Instructions file cannot b
found." & Chr(13) & "It may have been moved to another location."
Chr(13) & "Please browse your computer for the file.", vbOKOnly, "Fil
Not Found")
Call OpenWordDial

End Sub


Sub OpenWordDial()
Dim Wrd As New Word.Application
With Wrd.Dialogs(wdDialogFileOpen)
.Name = "*.doc"
.Show
End With
Set Wrd = Nothing

End Sub


Thanks so much in advance
 
J

jeff

Hi,

insert this after your label c: in OpenWord (before
your "msgbox...")

wdapp.Quit
Set WdApp = Nothing

jeff
-----Original Message-----
Hi! I'm hoping someone here can help me out with something that has
been frustrating me for awhile...

I want to open a word document from excel (with a button) and if it is
not found i want the open file dialog box to appear for the user to
browse for the document in case it has been moved.

I have come up with the following code and it works well except it
opens two instances of word if the file is not found. if the file is
found, there are no problems. Does anyone know how to fix the code so
that only one instance of excel will be open??



Sub OpenWord()
MyDoc = "C:\Documents and
Settings\dickisoh\Desktop\Work\CAA Year
 
H

HeatherD

Thanks so much Jeff!! That has been killing me for so long.

One more quick question... once the dialog comes up, if I choose t
hit cancel (instead of locating the file and hitting ok), a blan
instance of word stays open with no document. Is it possible to hav
word quite at the point as well??

Thanks again, you just made my life so much simpler
 
H

HeatherD

Sorry, one more thing. When I open the file with the dialog box, th
menu bars do not come up, although I can still use keyboard shortcut
such as ctrl-p. If the file is in the specified location, it open
with menubars and complete functionality.

Any suggestions? Ideally I want the document to be read-only, bu
allow the user to print it if they want
 
J

jeff

Hi,

Glad it worked for you. Yes, this code closes
the non-opened app.

jeff
=====================

Sub OpenWordDial()
Dim Wrd As New Word.Application
With Wrd.Dialogs(wdDialogFileOpen)
.Name = "*.doc"
.Show
End With
If Wrd.Documents.Count = 0 Then Wrd.Quit
Set Wrd = Nothing

End Sub
 
J

jeff

Hi again.

Sorry this one is beyond me - when I open my test
file, all the menubars come up. I'll have to think
on it a bit more..

jeff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top