Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 49956

Need help figuring out why macro is not attaching the new PDF to Outlook

$
0
0
Disclaimer: I'm new to Macros, so please be kind.

I have a Macro that does the following: Based on an existing excel worksheet, it looks at the Active worksheet, uses a drop down list for a particular dealer code, and changes the information on the active worksheet. it then generates a PDF and saves it to a location on my computer that was designated when it asked for the location to place the file. The issue with the Macro is it Does nearly everything correct, except for attaching the newly created PDF to the outlook message opened. In the excel file, it's pulling information to even capture the applicable email address which to email the file. It's current "displaying" before sending as I work to complete it. Again, the only step it's not doing is to actually attach the newly created PDF Files that were converted from Excel.

Here's the Code:

Code:

Sub DashboardToPDF()
Dim FolderName As String, Fname As String
Dim inputRange As Range, r As Range, c As Range
Dim EmailSubject As String, EmailSignature As String
Dim DestFolder As String, PDFFile As String
Dim Email_To As String, Email_CC As String, Email_BCC As String
Dim OpenPDFAfterCreating As Boolean, AlwaysOverwritePDF As Boolean, DisplayEmail As Boolean
Dim OverwritePDF As VbMsgBoxResult

Application.ScreenUpdating = False
'''' Open file dialog and choose folder
With Application.FileDialog(msoFileDialogFolderPicker)
    .AllowMultiSelect = False
    If .Show = True Then
        FolderName = .SelectedItems(1) & "\"
    Else
        Exit Sub
    End If
End With

'''' Location of DataValidation cell
Set r = Worksheets("Dashboard").Range("C1")
'''' Get DataValidation values
Set inputRange = Evaluate(r.Validation.Formula1)

'''' Loop through DataValidation list
For Each c In inputRange
    r.Value = c.Value
    Fname = c.Value
    '''' Save as pdf
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=FolderName & Fname, _
        Quality:=xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

'Working in Office 2000-2010
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)
 
    strbody = "Hi there" & vbNewLine & vbNewLine & _
              "Cell A1 is changed" & vbNewLine & _
              "The Excel Data is attached in PDF Format" & vbNewLine & _
              "This is line 3" & vbNewLine & _
              "This is line 4"

    On Error Resume Next
    With OutMail
        .To = Range("a28").Value
        .CC = ""
        .BCC = ""
        .Subject = "Collision & Mechanical PSX Sales"
        .Body = strbody
'''''this is area of code where I believe an .Attachment.Addxxxxx code goes*** i th
       
        .Display                    'or use .Send
       
           
    End With
    On Error GoTo 0

    Set OutMail = Nothing
    Set OutApp = Nothing

Next c
Application.ScreenUpdating = True


End Sub


Viewing all articles
Browse latest Browse all 49956

Trending Articles