Sending pdf as attachment

A

AJ

I am needing some direction. I am updating old coding on an inherited
program. It sends an access report through email using the SendObject. Now
the users want to mail merge into Word then change it to a PDF and then email
it. I understand that you cannot use the SendObject with a PDF attachment. So
my question is what is the easiest way to do this now. I am just needing to
call the document up to attach it. I have it programmed to go to PDF and
saved to a temp folder. I have the code set up for the email address, etc..I
am stuck with how to call the "C:\Temp\ETC" file to attach to the email. Help
will be appreciated very much, I have spent 1 week reading up on this on just
about every web site, and no direction yet. I just need to call the temp file
and attach to email. Like I said it is already coded to change to PDF etc...
Thank You so much,
AJ
 
P

Paul Shapiro

You didn't say how you're sending the email, but if the users have Word then
maybe they also have Outlook? You can create the Outlook application object,
then use that to create a MailItem. The MailItem has a method to set the
attachment. Something like this:
Set oOutlook = GetObject(, "Outlook.Application")
'Retrieve, or create, the Outlook application object
Set oOutlook = GetObject(, "Outlook.Application")
If oOutlook Is Nothing Then 'Start new object
Set oOutlook = CreateObject("Outlook.Application", "localhost")
If oOutlook Is Nothing Then
MsgBox "Could not initialize the Microsoft Outlook
Application", _
vbCritical, "Cannot send the message"
GoTo ExitHandler
End If
End If

Set oOutlookMsg = oOutlook.CreateItem(olMailItem)
With oOutlookMsg
.Subject = strSubject
.Body = strText
Set oRecipient = .Recipients.Add(strRecipient)
oRecipient.Type = olTo

'File exists. Attachments.Add _
Source- Full path and file name of the file to attach, _
Type- olByValue=1 to insert file, _
Position- location within the body to display the attachment
icon if sending Rich Mail Format, _
DisplayName- Label to display for the attachment
.Attachments.Add strAttachFileNamePath, olByValue, 1,
strFileNameOnly
'Display or send the email
If fPreviewMessage Then
.Display True
Else
.Send
End If
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top