A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

open word file, browse if not found



 
 
Thread Tools Display Modes
  #1  
Old August 4th, 2004, 06:33 PM
HeatherD
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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
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 be
found." & Chr(13) & "It may have been moved to another location." &
Chr(13) & "Please browse your computer for the file.", vbOKOnly, "File
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!


---
Message posted from http://www.ExcelForum.com/

  #2  
Old August 4th, 2004, 08:18 PM
jeff
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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
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 be
found." & Chr(13) & "It may have been moved to another

location." &
Chr(13) & "Please browse your computer for the file.",

vbOKOnly, "File
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!


---
Message posted from http://www.ExcelForum.com/

.

  #3  
Old August 4th, 2004, 08:40 PM
HeatherD
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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

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

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


---
Message posted from http://www.ExcelForum.com/

  #4  
Old August 4th, 2004, 08:51 PM
HeatherD
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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

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


---
Message posted from http://www.ExcelForum.com/

  #5  
Old August 5th, 2004, 02:51 PM
jeff
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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
-----Original Message-----
Thanks so much Jeff!! That has been killing me for so

long.

One more quick question... once the dialog comes up, if

I choose to
hit cancel (instead of locating the file and hitting

ok), a blank
instance of word stays open with no document. Is it

possible to have
word quite at the point as well??

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


---
Message posted from http://www.ExcelForum.com/

.

  #6  
Old August 5th, 2004, 02:53 PM
jeff
external usenet poster
 
Posts: n/a
Default open word file, browse if not found

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
-----Original Message-----
Sorry, one more thing. When I open the file with the

dialog box, the
menu bars do not come up, although I can still use

keyboard shortcuts
such as ctrl-p. If the file is in the specified

location, it opens
with menubars and complete functionality.

Any suggestions? Ideally I want the document to be read-

only, but
allow the user to print it if they want.


---
Message posted from http://www.ExcelForum.com/

.

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
changes to normal.dot Dianah New Users 7 June 17th, 2004 01:19 AM
Unsafe Attachments Ron Installation & Setup 2 June 9th, 2004 01:55 AM
Productkey problem when installing office 2003 on network Stefan Schreurs Setup, Installing & Configuration 1 June 1st, 2004 11:16 PM
"Excel file locked by [user]" though user is the one trying to open it! Lady Layla Setting up and Configuration 0 May 12th, 2004 02:12 PM
GPO Office 2003 Tony Setup, Installing & Configuration 1 May 12th, 2004 10:42 AM


All times are GMT +1. The time now is 09:46 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.