Have to working code that sends a workbook as PDF with outlook mail.I have a address book that it gets the name and email address from,problem is if
the person is not in address book I have problems. Is there a way to have a input box pop up to insert a email address if its not in main address book? Really
need to expert advice on this,not even sure if it can be done.
Thanks Z 
Const rootpath = "C:\Builder\master\temp"
Const CoName = "Bob's the Builder-"
Dim vinv As String
Dim vbuilder As String
Dim vjob As String
Dim vSaveAs As String
Sub PackageAndSend()
SaveAsPDF
Send_Files
On Error Resume Next
Kill vSaveAs 'Deletes the PDF file'
End Sub
Sub SaveAsPDF()
Const OpenPDF = False
vinv = CleanseString(Range("invoiceone"))
vbuilder = CleanseString(Range("builder"))
vjob = CleanseString(Range("C13"))
vSaveAs = rootpath & "\" & CoName & vinv & "-" & vbuilder & "-" & vjob & ".pdf"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
vSaveAs, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=True, _
From:=1, To:=1, _
OpenAfterPublish:=OpenPDF
End Sub
Sub Send_Files()
Dim OutApp As Object
Dim OutMail As Object
Dim AddBook As Worksheet
Dim Found As Range
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set AddBook = Sheets("Address Book")
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
vbuilder = Range("builderone")
Rem Set Found = AddBook.Range("A:A").Find(What:=vbuilder, _
After:=Range("A1"))
currsht = ActiveSheet.Name
AddBook.Activate
Set Found = AddBook.Columns("A:A").Find(What:=vbuilder, _
After:=Range("A1"), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False, SearchFormat:=False)
If Not Found Is Nothing Then
vEmailAddress = Found.Offset(0, 4)
End If
vBody = vbuilder & ";" & vbLf
vBody = vBody & vbLf & vbLf
vBody = vBody & "See the attached PDF file ." & vbLf
vBody = vBody & "" & vbLf
vBody = vBody & "" & vbLf
vBody = vBody & CoName
With OutMail
.To = vEmailAddress
.Subject = CoName & "-" & vinv & "-" & vjob
.Body = vBody
If Dir(vSaveAs) <> "" Then
.Attachments.Add vSaveAs
End If
If Trim(.To) = "" Then
MsgBox ("Your trying to sent an Email that is not in the (AddressBook),you must (Open Outlook) and minimized it before you try and send!")
End If
If Trim(.To) = "" Then
.send
Else
.send 'use .send or .display
End If
End With
Sheets(currsht).Activate
Set OutMail = Nothing
Set OutApp = Nothing
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
End Sub
Bookmarks