Vba to attach a file using cell reference

Revathi

New Member
Joined
May 26, 2015
Messages
34
Hi all,

i need to attach a file in a outlook from my local path wherein the path keeps changing in a daily basis however it would be better for me if i do a changes in a cell reference instead of directly in the macro. below is the syntax which i directly keep changing the path in the macro which is not suitable for me.

2. and also i want to attach a file using the first 3 letter of the file name.

.Attachments.Add "Z:\COMMON\\2018\Mar\07\ATL.xlsx"

Anyone can help on this.
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
If your value is in b1 (for example) then it should be Z:\common\2018\mar\07\atl.xslx - no quotes needed

change your attachments to and it should attach

Code:
 .attachments.Add Range("b1").Value

if it always on the Z drive then you can limit the amount you need to type by something like below, which means that b1 would only need 2018\mar\atl.xslx

Code:
.attachments.Add "Z:\common\" & Range("b1").Value

Hope this all makes sense, post back if note :)
 
Upvote 0
Thanks a lot..it works fine.. but is it possible that i can attach a file using the first 3 letter of the file name since i have dates in the file name wherein it keep changing daily. Hence it would be better for me if i refer the first 3 letter of the file name to attach.
 
Upvote 0
... it would be better for me if i refer the first 3 letter of the file name to attach.


Maybe this...

Put '2018\Mar\07\' without the quotes in cell B1
Put 'ATL' without the quotes in cell C1

Then replace this line...
Code:
.attachments.Add "Z:\common\" & Range("b1").Value

...with this line...
Code:
 .Attachments.Add "Z:\COMMON\" & cells(1,"B") & cells(1,"C") & ".xlsx"
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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