avoiding hard coding current directory file path (1 Viewer)

KirRoyale

Registered User.
Local time
Tomorrow, 01:39
Joined
Apr 22, 2013
Messages
61
I have a piece of code to open a Word document. I would like to use the ‘current project.path’ instead of hard coding the directory path but cannot seem to get the right code / syntax.

Private Sub OpenWordDocument_Click()
Dim oApp As Object
Dim strDocName As String
strDocName = "C:/Documents/Instructions.docx"
Set oApp = CreateObject("Word.Application")
oApp.Visible = True
oApp.Documents.Open strDocName
End Sub

Could somebody please help?
 

Galaxiom

Super Moderator
Staff member
Local time
Tomorrow, 02:39
Joined
Jan 20, 2009
Messages
12,854
strDocName = CurrentProject.Path & "\" & somefilename

Note that Microsoft uses backslashes.
 

KirRoyale

Registered User.
Local time
Tomorrow, 01:39
Joined
Apr 22, 2013
Messages
61
Thank you - that works.
 

Users who are viewing this thread

Top Bottom