I have tried to search and can't find anyone reporting a similar question/problem.
I have a macro that filters some data, and then creates a PDF file from the filtered data, so far no problem. Then I have a macro that then sends the PDF file as an attachment in an email, but the problem is that when I do this, the PDF file that it sends is blank, there is no data in the PDF file that is sent. I know that the PDF that is initially created is fine, as I can go to the PDF file to look at it, and the data is there. But then when I send it as part of a macro, it seems the data is somehow stripped out? the PDF that gets sent is as many pages as the original PDF file was, so if the PDF was 4 pages, then it sends 4 pages, it is just that they are empty pages! In my most recent example of trying this, the PDF created is 267kb, but what gets attached and sent then becomes 140kb.
Here is a part of the macro I use to create the initial PDF:
Here is the code in the macro to send the file:
I just do not understand what is going on, maybe I am missing something basic?
I have a macro that filters some data, and then creates a PDF file from the filtered data, so far no problem. Then I have a macro that then sends the PDF file as an attachment in an email, but the problem is that when I do this, the PDF file that it sends is blank, there is no data in the PDF file that is sent. I know that the PDF that is initially created is fine, as I can go to the PDF file to look at it, and the data is there. But then when I send it as part of a macro, it seems the data is somehow stripped out? the PDF that gets sent is as many pages as the original PDF file was, so if the PDF was 4 pages, then it sends 4 pages, it is just that they are empty pages! In my most recent example of trying this, the PDF created is 267kb, but what gets attached and sent then becomes 140kb.
Here is a part of the macro I use to create the initial PDF:
VBA Code:
PDFFilename = "Current Residents " & Format(Now(), "YYYYMMDD") & ".pdf"
Application.CutCopyMode = False
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.PrintTitleRows = "$1:$1"
.LeftMargin = Application.InchesToPoints(0.31496062992126)
.RightMargin = Application.InchesToPoints(0.31496062992126)
.TopMargin = Application.InchesToPoints(0.354330708661417)
.BottomMargin = Application.InchesToPoints(0.354330708661417)
.Orientation = xlPortrait
.PaperSize = xlPaperA4
.FitToPagesWide = 1
.FitToPagesTall = False
End With
Application.PrintCommunication = True
Application.DisplayAlerts = False
ActiveWorkbook.ActiveSheet.UsedRange.ExportAsFixedFormat Type:=xlTypePDF, _
Filename:=FilePath & PDFFilename, _
Quality:=xlQualityStandard, _
IncludeDocProperties:=True, _
IgnorePrintAreas:=False, _
OpenAfterPublish:=False
Application.DisplayAlerts = True
Here is the code in the macro to send the file:
VBA Code:
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set SourceWb = ThisWorkbook
FilePath = SourceWb.Path & "\"
Columns("M:M").Select
Selection.EntireColumn.Hidden = True
PDFFilename = "Current Residents " & Format(Now(), "YYYYMMDD") & ".pdf"
iConf.Load -1 ' CDO Source Defaults
Set Flds = iConf.Fields
With Flds
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "source email here"
.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "email password here"
.Update
End With
With iMsg
Set .Configuration = iConf
.To = "target email here"
.CC = ""
.BCC = ""
.From = "source email here"
.Subject = "Current Residents " & Format(Now(), "dd/mm/yyyy")
.addAttachment FilePath & PDFFilename
.Send
End With
Set iMsg = Nothing
Set iConf = Nothing
Set Flds = Nothing
I just do not understand what is going on, maybe I am missing something basic?