Solved Opening document without full Path

stu_c

Registered User.
Local time
Today, 10:44
Joined
Sep 20, 2007
Messages
494
Hi all
I am currently using the below code to open a document
Code:
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("C:\Users\Databases\HRRecords\Reports\HRReportFile.docx")

Is there a way to only get access to search for the document within the main folder path rather than the whole CDrive, for example I know with HTML etc you can put ../ etc, the issue I have is if the database gets moved to another drive then I need to manually change the file path so it still looks for it in the correct place? if it cannot be done its not a big issue

Example of how I mean
Code:
    Set oWd = CreateObject("Word.Application")
    Set oDoc = oWd.Documents.Add("..\Reports\HRReportFile.docx")
 
Last edited:
Why would you open an excel file with Word?
 
I always use

CurrentProject.Path

So in your case it should be something like :

Set oDoc = oWd.Documents.Add(CurrentProject.Path & "\Reports\HRReportFile.docx")
 
I always use

CurrentProject.Path

So in your case it should be something like :

Set oDoc = oWd.Documents.Add(CurrentProject.Path & "\Reports\HRReportFile.docx")
thank you!
 

Users who are viewing this thread

Back
Top Bottom