Help with code to access a file

zoog25

Active Member
Joined
Nov 21, 2011
Messages
418
Hello all,

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.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
That should be fine. :)
 
Upvote 0
Solution

Forum statistics

Threads
1,215,470
Messages
6,124,992
Members
449,201
Latest member
Lunzwe73

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top