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

VBA Word open/close document

Status
Not open for further replies.

nme187

Technical User
Apr 29, 2008
4
US
Hello everyone,

I'm trying to make wdDialogFileOpen open a docuent(.doc) when the user chooses one and close the current document. If I have a document open and try to open a different one then it works fine but if theres no current document open then it errors. I need a check if a document is open then close and open the new one. Here's what I have so far. Thanks in advance.

Private Sub cmdopen_Click()

Dim sFileName As String

With Application.Dialogs(wdDialogFileOpen)
.Display
sFileName = .Name
End With

If sFileName <> "" Then
'ActiveDocument.Close
Documents.Close
Documents.Open filename:=sFileName
End If

documentName = Word.ActiveDocument.Name
End Sub
 
If Documents.Count > 0 Then
Documents.Close
End If

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Haha awesome thanks man >.< I couldn't think of it
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top