Hello all,
I currently using the following code for a project I'm working on.
As you can see, the code looks for a particular file path to open the file. I used Dir() to see if that file exists. I'm not sure if this is the correct way to check to see if a file exists.
I currently using the following code for a project I'm working on.
VBA Code:
wfile = ActiveWorkbook.Path & "\Agreements\Improvement.Agr-2Party.docx"
If Dir(wfile) <> "" Then
Wordapp.Documents.Open (wfile)
Wordapp.Visible = True
Else
MsgBox "Link to file is missing, please use explorer window to select the Improvement.Agr-2Party document "
Dim fd As Object
Set fd = Application.FileDialog(3)
With fd
If .Show Then
selectFile = .SelectedItems(1)
Wordapp.Documents.Open (selectFile)
Wordapp.Visible = True
Else
MsgBox ("Since no file is selected. No Agreement will be drafted.")
Exit Sub
End If
End With
Set fd = Nothing
End If
As you can see, the code looks for a particular file path to open the file. I used Dir() to see if that file exists. I'm not sure if this is the correct way to check to see if a file exists.