Hi gurus,
how can i get dialogue box in VBA for attachments before sending email ?
I'm currently using the following code and it creates PDF file which is fine but I also want some other files to attach with the email, however I'd like it to select it manually rather than defining the path. Please can someone guide me on this.
Many thanks,
Private Sub CommandButton1_Click()
Dim IsCreated As Boolean
Dim i As Long
Dim PdfFile As String, Title As String
Dim OutlApp As Object
' 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)
CarryOn = MsgBox("ARE YOU SURE?", vbYesNo, "TEST")
If CarryOn = vbYes Then
' Prepare e-mail
.Subject = "XYZ"
.To = "XYZ@XYZ.COM"
.Body = "Hi," & vbLf & vbLf _
& "XYZ." & vbLf & vbLf _
& "XYZ," & 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 If
End With
' Delete PDF file
Kill PdfFile
' Release the memory of object variable
Set OutlApp = Nothing
End Sub
Bookmarks