macro email HELP WITH CODE

Youseepooo

New Member
Joined
Feb 5, 2019
Messages
37
Hello,
I have this code that sends out an email via a button, however my last table is not appearing when it publishes as PDF. I made sure the table is within the range of the code but it still inst appearing. Any suggestions?


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\PCC Daily Schedule\2019 March"
    wFile = "Daily Look Ahead for " & x & ".pdf"
      Range("B1:G82").ExportAsFixedFormat Type:=xlTypePDF, Filename:=wPath & "\" & wFile, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, _
        IgnorePrintAreas:=False, OpenAfterPublish:=False
     
        ActiveSheet.PageSetup.PrintArea = myRange
        
        
With ActiveSheet.PageSetup
    .LeftMargin = Application.InchesToPoints(0.5)
    .RightMargin = Application.InchesToPoints(0.5)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.5)
    .HeaderMargin = Application.InchesToPoints(0.2)
    .FooterMargin = Application.InchesToPoints(0.1)
    .PaperSize = xlPaperA4
    .Orientation = xlPortrait 'xlLandscape
    .Zoom = False
    .FitToPagesWide = 1
    .FitToPagesTall = False
    
        End With
        
    
    strPathToImageFolder = "C:\Users\ymussa\Pictures\Camera Roll"
    
    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<br>E Mail:    ymussa@perfettocontracting.com"
    
    Set dam = CreateObject("Outlook.Application").CreateItem(0)
    
    With dam
    .to = "ymussa@perfettocontracting.com;sascoli@perfettocontracting.com;JNascimento@perfettocontracting.com;TBucciarelli@perfettocontracting.com;broe@perfettocontracting.com;rtitov@perfettocontracting.com;jsilko@perfettocontracting.com;jmiranda@perfettocontracting.com;cperfetto@perfettocontracting.com;cperfettojr@perfettocontracting.com;ppopielarski@perfettocontracting.com;fmarriott@perfettocontracting.com;PFiguera@perfettocontracting.com;nzarelli@perfettocontracting.com;acolandro@perfettocontracting.com  "
        .cc = "mperfetto@perfettocontracting.com;AEmirtepe@perfettocontracting.com;hmohammed@perfettocontracting.com;TBolgiani@perfettocontracting.com"
        .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
 

Some videos you may like

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

daverunt

Well-known Member
Joined
Jul 9, 2009
Messages
1,846
Office Version
  1. 2013
Platform
  1. Windows
Hi,

it isn't clear what HTML is in your code. You use HTML tags instead of CODE tags around it.

I would suggest using the function RangetoHTML from this link to process the table range.

https://www.rondebruin.nl/win/s1/outlook/bmail2.htm

Untried example
https://www.vba-market.com/excel-vba-insert-excel-table-into-body-of-email-message/

You can add the table at any point within a mail if you have other text to add around it:

.HTMLBody = "Dear Sir" & vbNewline & vbNewline & RangetoHTML(Rng) & VBNewline

etc...
 

Watch MrExcel Video

Forum statistics

Threads
1,109,204
Messages
5,527,410
Members
409,760
Latest member
zeeshansyed

This Week's Hot Topics

Top