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
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