HI all,
I found this bit of coding on here, so if the person that wrote it see this then I am very impressed. However I wanted some advice on how to customise it. I have attached the coding below.
If there is someone clever enough to be able to help I would be forever grateful.
I found this bit of coding on here, so if the person that wrote it see this then I am very impressed. However I wanted some advice on how to customise it. I have attached the coding below.
- I was wanting to be able to specify the sheets it creates as a PDF, the result being that there maybe three pages created in a PDF from a workbook book with 5 sheets.
- I wanted to add another e-mail address to the CC field
If there is someone clever enough to be able to help I would be forever grateful.
Code:
Private Sub CommandButton1_Click()
Sub AttachActiveSheetPDF()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' Not sure for what the Title is
Title = Range("A1")
' Define PDF filename
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = PdfFile & "_" & ActiveSheet.Name & ".pdf"
' Export activesheet as PDF
With ActiveSheet
.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PdfFile, Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
End With
' Use already open Outlook if possible
On Error Resume Next
Set OutlApp = GetObject(, "Outlook.Application")
If Err Then
Set OutlApp = CreateObject("Outlook.Application")
IsCreated = True
End If
OutlApp.Visible = True
On Error GoTo 0
' Prepare e-mail with PDF attachment
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = Title
.To = "mainemail@mail.co.uk"
.CC = "otheremail@mail.co.uk" (Bit of coding to add another email address)
.Body = "Hi all," & vbLf & vbLf _
& "Here is a deal we are looking at, PDF attached" & vbLf & vbLf _
& "Regards,Chris & John" & vbLf _
& Application.UserName & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
.Send
Application.Visible = True
If Err Then
MsgBox "E-mail was not sent", vbExclamation
Else
MsgBox "E-mail successfully sent", vbInformation
End If
On Error GoTo 0
End With
' Delete PDF file
Kill PdfFile
' Quit Outlook if it was created by this code
If IsCreated Then OutlApp.Quit
' Release the memory of object variable
Set OutlApp = Nothing
End Sub
Last edited by a moderator: