How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Ansh P. Your Own Question
Ansh P.
Ansh P., Computer Software Specialist
Category: Programming
Satisfied Customers: 8148
Experience:  Professional software developer working as a systems engineer in top multi-national company.
14055801
Type Your Programming Question Here...
Ansh P. is online now
A new question is answered every 9 seconds

I need a outlook macro that can insert a specific attachment

This answer was rated:

I need a outlook macro that can insert a specific attachment that I use over and over. I don't need the macro to send the email. Just insert the attachment while I am replying to a customer request. I'm using outlook 2010.
Hi

Welcome to JustAnswer.com

I am Coding Guru and today, I will be trying my best to solve your issue.

Please use the below macro:

Sub SendMailWithAttachment()

Dim OutlookApp As Object
Dim pdf As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set pdf = OutlookApp.CreateItem(0)


With pdf
.To = ""
.Subject = ""
.Body = ""
.Attachments.Add "C:\Macros\Tata.pdf"
pdf.Display
End With


Replace the C:\Macros\Tata.pdf with the path of your attachment. If you have any queries, let me know.
Customer: replied 3 years ago.

I don't want to send the email nor do I need to update the subject line. I would be replying to a customer inquiry. Each one is unique. I just want the macro to insert the attachment. That is all.

Thanks Gary.

You can use the below:

IMPORTANT part is, you have to replace the path C:\Macros\Tata.pdf where your pdf file is stored. For example, if it's stored in a folder called Test in D drive, the path will be D:\Test\abc.pdf, where abc.pdf is the file name.


Sub SendMailWithAttachment()

Dim OutlookApp As Object
Dim pdf As Object

Set OutlookApp = CreateObject("Outlook.Application")
Set pdf = OutlookApp.CreateItem(0)


With pdf
.Attachments.Add "C:\Macros\Tata.pdf"
pdf.Display
End With
Customer: replied 3 years ago.

I tried and receive a compilation error. Sub SendMailWithAttachment() is highlighted in yellow and below End With is says end sub is expected.

Gary, please give me 10 minutes. I will modify the code to attach the pdf in an existing mail, the above code is for opening a new outlook window with attachment in it.

'Use the below:

Sub SendMailWithAttachment()

Dim CurrentMessage As MailItem
Set CurrentMessage = ActiveInspector.CurrentItem

CurrentMessage.Attachments.Add "C:\Macros\Tata.pdf"

End Sub

 

 

'Make sure to change the attachment path.

Customer: replied 3 years ago.

Received another compile error. CurrentMessage.Attachments.Add C:\test.pdf" was highlighted in red and Sub SendMailWithAttachment() was in yellow

Try this:

Sub SendMailWithAttachment()

Dim CurrentMessage As MailItem
Set CurrentMessage = ActiveInspector.CurrentItem

CurrentMessage.Attachments.Add "C:\test.pdf"

End Sub


Also, is the test.pdf file stored in C: drive?
Ansh P. and 2 other Programming Specialists are ready to help you
Customer: replied 3 years ago.

It worked. Great job. I had 5 other gurus who could not figure this out.

Thank you. Glad to know that it worked.

Have a nice day. Please do not forget to leave me a rating.

Attachments are only available to registered users.

Register Here
Customer: replied 3 years ago.

I have another project. Can you program a custom addin? I would like a custom rule that would move emails that have specific words in the subject line and specific phrases in first 15 words of the body of the email to a specific folder.


 


Is this doable?