Referring to files in same folder as workbook in VBA

Adnan_razaq

New Member
Joined
Nov 14, 2019
Messages
11
Hi,

I'm trying to put piece of VBA code together to attach some PDF files in outlook and send out.

However, I sometimes work from my personal laptop and my business laptop. How can I code something like this

VBA Code:
.Attachments.Add "C:\Users\arazaq\Documents\Black\PDF Reports\Demo PDF\UK FTSE 100 Equity.pdf"

So that if I open the workbook on a another machine I would not need to to re-map the location of the PDF files to be attached. The PDF files are stored in the same folder as the workbook

Many Thanks in advance
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
You can get the path to the workbook the code is in using ThisWorkbook.Path.
 
Upvote 0
just tried this and it failed

VBA Code:
.Attachments.Add "ThisWorkbook.Path.\PDF Reports\Demo PDF\UK FTSE 100 Equity.pdf"

Thanks
 
Upvote 0
It would be:

Code:
.Attachments.Add ThisWorkbook.Path & "\PDF Reports\Demo PDF\UK FTSE 100 Equity.pdf"
 
Upvote 0
I usually go for something like this.
VBA Code:
.Attachments.Add ThisWorkbook.Path & Application.PathSeparator & "UK FTSE 100 Equity.pdf"
 
Upvote 0

Forum statistics

Threads
1,214,998
Messages
6,122,639
Members
449,093
Latest member
Ahmad123098

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