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
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
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...
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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