countryfan_nt
Well-known Member
- Joined
- May 19, 2004
- Messages
- 765
Hello friends, Hope all is well!
The code below does work. it sends a sheet as PDF via Outlook.
Please help me edit the code, so that it sends a sheet as PDF withOUT Outlook; but CDO.
Your kind is needed and really appreciated in advance!
The code below does work. it sends a sheet as PDF via Outlook.
Please help me edit the code, so that it sends a sheet as PDF withOUT Outlook; but CDO.
Your kind is needed and really appreciated in advance!
Code:
Private Sub Email()
Set OutApp = GetObject(, "Outlook.Application")
Dim IsCreated As Boolean
Dim i As Long
Dim ab, ac, ad, emTo, emCC As String
Dim PdfFile As String, Title As String
Dim OutlApp As Object
emTo = Worksheets("PDF").Range("BD4").Value
emCC = Worksheets("PDF").Range("BD5").Value
ab = Worksheets("PDF").Range("B1").Value
GREET = Worksheets("PDF").Range("AZ4").Value
AMPM = Worksheets("PDF").Range("AZ6").Value
Set xSht = ThisWorkbook.Sheets("PDF")
Title = AMPM & " - " & Sheets("PDF").Range("G1")
TitleF = AMPM & " Period Update - " & Format(ab, "ddd dd-mmm-yyyy") & " - Medical Gas Inspection Summary."
PdfFile = ActiveWorkbook.FullName
i = InStrRev(PdfFile, ".")
If i > 1 Then PdfFile = Left(PdfFile, i - 1)
PdfFile = AMPM & " Period Update - " & Format(ab, "ddd dd-mmm-yyyy") & " - Medical Gas Inspection Summary" & ".pdf"
Sheets("PDF").Visible = True
xSht.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=PdfFile, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
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
With OutlApp.CreateItem(0)
' Prepare e-mail
.Subject = TitleF
.to = emTo ' <-- Put email of the recipient here
.CC = emCC ' <-- Put email of 'copy to' recipient here
.HTMLBody = GREET & vbLf & vbLf _
& "<p> The attachment here displays the findings of the inspections of all the medical gasses (per location & Branch)." & vbLf _
& "<p> Whethere the they were actually inspected or not, and what what are the results are after a physical visit." & vbLf _
& "<p><i>Two emails will be sent on daily basis (weekends not included)</i>" & vbLf & vbLf _
& "<p><p>Best Regards,<br>" & vbLf _
& " " & vbLf & vbLf
.Attachments.Add PdfFile
' Try to send
On Error Resume Next
Set .SendUsingAccount = OutlApp.Session.Accounts.Item(1) 'Use 2nd Account in the list
.DISPLAY
Application.Wait (Now + TimeValue("0:00:01"))
Application.SendKeys "%s"
Application.Visible = True
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
Sheets("PDF").Visible = False
End Sub