Send email code Error 1004

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 ?

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
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
Re: EXCEL Send email code Error 1004

You have an invalid path and filename. You've added a backslash (\) to wPath, and then you add another backslash when you define the path and filename for your argument. So try removing it from wPath..

Code:
[COLOR=#574123]wPath = "J:\Schedules"[/COLOR]

Hope this helps!
 
Upvote 0
Re: EXCEL Send email code Error 1004

No I just removed that section for privacy of my network lol and forgot to erase the extra backslash it’s not working and I made sure there’s no copies of it open anywhere so I’m confused.
 
Upvote 0
Re: EXCEL Send email code Error 1004

Try running your code again, but this time when the error occurs and you click Debug and then it takes to to the line causing the error, enter the following line of code in the Immediate Window (Ctrl+G) and press ENTER...

Code:
? dir(wPath & "\" & wFile, vbNormal)

Does it return the file name?
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,004
Members
452,374
Latest member
keccles

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top