Youseepooo
New Member
- Joined
- Feb 5, 2019
- Messages
- 37
I keep getting the error 1004 saying document not saved in this code that saves to pdf and emails ?
what is wrong with it can any one help ?
the part that highlights is :
Sheets("Daily Look Ahead").Range("B1:G95").ExportAsFixedFormat Type:=xlTypePDF, Filename:=wPath & "" & wFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
what is wrong with it can any one help ?
Code:
Sub Send_Email()
Dim dam As Object
Dim wPath As String
Dim wFile As String
Dim x As String
Dim wf As WorksheetFunction
Dim myRange As String
Dim strPathToImageFolder As String
Dim strImageFilename As String
Dim strHTML As String
Set wf = Application.WorksheetFunction
x = Format(wf.WorkDay(Date, 1), "MMMM dd, yyyy")
wPath = "J:\Schedules\"
wFile = "Daily Look Ahead for " & x & ".pdf"
Sheets("Daily Look Ahead").Range("B1:G95").ExportAsFixedFormat Type:=xlTypePDF, Filename:=wPath & "\" & wFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True
ActiveSheet.PageSetup.PrintArea = myRange
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
.HeaderMargin = Application.InchesToPoints(0.2)
.FooterMargin = Application.InchesToPoints(0.1)
.PaperSize = xlPaperA4
.Orientation = xlPortrait 'xlLandscape
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 2
End With
strPathToImageFolder = "C:\Users\"
If Right(strPathToImageFolder, 1) <> "\" Then
strPathToImageFolder = strPathToImageFolder & "\"
End If
strImageFilename = "pcc.jpg"
strHTML = "<p>Hello all,</p>"
strHTML = strHTML & "<p>The Daily Look Ahead Schedule for " & x & " is attached.<p><p>"
strHTML = strHTML & "<br>Thank You<br>Yousef Mussa<br>Assistant Engineer<br><img src=""cid:" & strImageFilename & """><p> Perfetto Contracting Co. Inc.<br>152 - 41 St Street<br>Brooklyn, NY 11232</p>Office: 718-858-8600 Ext. 166<br>Fax: 718-858-8604
Set dam = CreateObject("Outlook.Application").CreateItem(0)
With dam
.to = " "
.cc = ""
.Subject = "Daily Schedule for " & x
.attachments.Add wPath & "\" & wFile
.attachments.Add strPathToImageFolder & strImageFilename
.htmlbody = strHTML
.display
End With
Set dam = Nothing
MsgBox "Email sent"
End Sub
the part that highlights is :
Sheets("Daily Look Ahead").Range("B1:G95").ExportAsFixedFormat Type:=xlTypePDF, Filename:=wPath & "" & wFile, _
Quality:=xlQualityStandard, IncludeDocProperties:=True, _
IgnorePrintAreas:=False, OpenAfterPublish:=True