Opening a PDF file within same folder as workbook

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Opening a PDF file within same folder as workbook

Post by ABabeNChrist »

I have a workbook and a PDF file that are located within the same folder. At the present moment I use this method to open PDF file from this same workbook. Is there a code that I can use to open this same PDF file even though I may move entire folder that holds both workbook and PDF file to another location. Kind of like the word approach with “ThisWorkbook.Path”

Code: Select all

Dim strFile As String
  ' Path and filename of PDF file
  strFile = "C:\Program Files\Folder Name\File Name.pdf"
  ActiveWorkbook.FollowHyperlink strFile

User avatar
HansV
Administrator
Posts: 78236
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Opening a PDF file within same folder as workbook

Post by HansV »

Use

strFile = ThisWorkbook.Path & "\File Name.pdf"
Best wishes,
Hans

ABabeNChrist
SilverLounger
Posts: 1868
Joined: 25 Jan 2010, 14:00
Location: Conroe, Texas

Re: Opening a PDF file within same folder as workbook

Post by ABabeNChrist »

Thank you HansV
Worked like a charm :clapping: