[RESOLVED] Email PDF from VBA Code?
I have written code to create PDF's in excel. I was wondering if it is possible, that after I create the PDF, to email that PDF file to a specified recipient. Any help or suggestions would be greatly appreciated.....even if the answer is "It's not possible". This way I don't keep racking my brain trying to find a solution. Thanks!
Re: Email PDF from VBA Code?
You should be able to program Outlook from Excel to send it as an attachment, assuming you have Outlook. Don't know how you'd do it with other email programs.
Re: Email PDF from VBA Code?
Yes, I have Outlook but I don't know how to code this with an attachement. I can easily send excel workbooks but not other file extension attachements.
Re: Email PDF from VBA Code?
Sure its possible. You can use the Outlook Object Model inside of Excel but you will get the Security Prompt, which is no big deal since your not doing a batch mailing or stuff.
Search by my username and outlook and attachment and you should find many examples to go over. :)
Re: Email PDF from VBA Code?
Actualy I will be doing batch emailing. There may be 100 different PDF's created (one for each supplier). I then would like to send just that PDF to the corrisponding supplier. Apparently the security prompt will be an issue. Is there anyway around this? Also, I have tried a search with your suggestion but I'm not having luck finding the simple code to send an email with an attachement.
Re: Email PDF from VBA Code?
Here is a result from my search. Some code of mine from a few years ago.
http://www.vbforums.com/showpost.php...52&postcount=4
Re: Email PDF from VBA Code?
There is no way in VB to bypass the prompt without re-writting your app as an Outlook Add-In or by using a third party product. Third party products all require the system to be logged on and not locked.
Re: Email PDF from VBA Code?
Here's an example from an app from last year in VB.Net. The principle of programming outlook should be similar.
VB Code:
Public Sub LetsSendMail()
Dim OlApp As New Outlook.Application()
Dim OlNameSpace As Outlook.NameSpace
Dim msg As Outlook.MailItem
Dim strPath, strSubj, strName As String
strPath = strRelPath & gstrPepType & "\" & Current.Proj & "\" & Current.Proj & "Changes.txt"
strSubj = Current.Proj & " " & Current.Mnth.ToUpper & ", " & Current.YNum & " Edited Changes"
strName = "Your client's email"
Try
msg = OlApp.CreateItem(Outlook.OlItemType.olMailItem)
msg.Recipients.Add(strName)
msg.Subject = strSubj
msg.Attachments.Add(strPath)
msg.Body = "Changes attached for " & Current.Mnth.ToUpper & Current.Proj.ToUpper
msg.Display()
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
This doesn't send the email, because I review it first. You may want to get client's emails & which the path to their pdf from a table or file. Put it in a loop to send multiple emails. I don't know any way to avoid sending 50 separate emails if all 50 clients get a separate attachment, though.
Re: Email PDF from VBA Code?
I got it working. Thanks for the help!