Results 1 to 27 of 27

Change macro to send as excel file not pdf.

Threaded View

And180y Change macro to send as excel... 11-13-2020, 02:15 PM
Logit Re: Change macro to send as... 11-13-2020, 06:22 PM
And180y Re: Change macro to send as... 11-18-2020, 03:48 PM
maniacb Re: Change macro to send as... 11-22-2020, 01:42 AM
And180y Re: Change macro to send as... 11-27-2020, 05:43 PM
maniacb Re: Change macro to send as... 11-28-2020, 08:26 AM
And180y Re: Change macro to send as... 11-29-2020, 07:24 PM
maniacb Re: Change macro to send as... 12-01-2020, 06:20 PM
And180y Re: Change macro to send as... 12-01-2020, 06:24 PM
maniacb Re: Change macro to send as... 12-01-2020, 09:31 PM
And180y Re: Change macro to send as... 12-02-2020, 05:25 PM
And180y Re: Change macro to send as... 12-02-2020, 06:12 PM
maniacb Re: Change macro to send as... 12-02-2020, 07:41 PM
And180y Re: Change macro to send as... 12-02-2020, 08:04 PM
maniacb Re: Change macro to send as... 12-02-2020, 10:05 PM
And180y Re: Change macro to send as... 12-03-2020, 04:58 PM
maniacb Re: Change macro to send as... 12-04-2020, 12:00 PM
And180y Re: Change macro to send as... 12-04-2020, 07:24 PM
maniacb Re: Change macro to send as... 12-04-2020, 08:46 PM
And180y Re: Change macro to send as... 12-04-2020, 09:18 PM
maniacb Re: Change macro to send as... 12-04-2020, 11:11 PM
And180y Re: Change macro to send as... 12-05-2020, 05:11 PM
And180y Re: Change macro to send as... 12-12-2020, 08:18 PM
maniacb Re: Change macro to send as... 12-12-2020, 11:13 PM
And180y Re: Change macro to send as... 12-14-2020, 10:20 PM
maniacb Re: Change macro to send as... 04-25-2021, 01:05 AM
maniacb Re: Change macro to send as... 04-30-2021, 04:17 PM
  1. #1
    Forum Contributor
    Join Date
    02-28-2020
    Location
    Inverness, Scotland
    MS-Off Ver
    365
    Posts
    308

    Change macro to send as excel file not pdf.

    I have the macro below but need it to send the pivot table as an excel file and not a pdf.
    I have searched around but not found any clues. Grateful for any help


    Sub EmailPTReports()
    
        Dim pt As PivotTable
        Dim pf As PivotField
        Dim pi As PivotItem
        Dim i As Long
        Dim EmailSubject As String
        Dim PDFFile As String
        Dim Email_To As String, Email_CC As String, Email_BCC As String
        Dim DisplayEmail As Boolean
        Dim OutlookApp As Object, OutlookMail As Object
    
        ' *****     You Can Change The Values of These Variables    *********
        EmailSubject = "Report" 'Change this to change the subject of the email.
        DisplayEmail = True 'Change this if you don't want to display the email before sending.  Note, you must have a TO email address specified for this to work
        Email_To = "" 'Change this if you want to specify To email e.g. ActiveSheet.Range("H1") to get email from cell H1
        Email_CC = ""
        Email_BCC = ""
        ' ******************************************************
    
        Set pt = Sheets("Pivot Table").PivotTables("PivotTable1")
        pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
        pt.PivotCache.Refresh
        
        Set pf = pt.PivotFields("Category")
        
        Set OutlookApp = CreateObject("Outlook.Application")
    
        ' Setup the sheet to print one 1 page
        Application.PrintCommunication = False
        
        With ActiveSheet.PageSetup
            
            .FitToPagesWide = 1
            .FitToPagesTall = 1
            .Orientation = xlLandscape
            
        End With
        
        Application.PrintCommunication = True
    
        ' Go through every category in turn
        For i = 1 To pf.PivotItems.Count
                      
            pf.CurrentPage = pf.PivotItems(i).name
            PDFFile = Environ("Temp") & Application.PathSeparator & pf.PivotItems(i).name & ".pdf"
            
            ' Replace / in category name as this is an invalid character for filenames
            PDFFile = Replace(PDFFile, "/", "_")
               
            ' Delete PDFFile if it already exists so that
            ' we can create new file later with the same name
            On Error Resume Next
            If Len(Dir(PDFFile)) > 0 Then Kill PDFFile
            
            ' If there's an error deleting the file
            If Err.Number <> 0 Then
            
                MsgBox "Unable to delete " & PDFFile & ".  Please make sure the file is not open or write protected." _
                        & vbCrLf & vbCrLf & "Press OK to exit this macro.", vbCritical, "Unable to Delete File"
                    
                Exit Sub
                        
            End If
            
            ' Reset error handling to normal
            On Error GoTo 0
                
            'Create the PDF
            ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:=PDFFile, Quality:=xlQualityStandard, _
            IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=False
    
            'Create a new mail message
            Set OutlookMail = OutlookApp.CreateItem(0)
            
            'Display email and specify To, Subject, etc
            With OutlookMail
            
                .Display
                .To = WorksheetFunction.VLookup(Range("B1").Value, Worksheets("Managers").Range("Managers"), 2)
                '.CC = Email_CC
                '.BCC = Email_BCC
                .Subject = EmailSubject
                .Attachments.Add PDFFile
                    
                ' Change this to True to automatically send emails without first viewing them
                If DisplayEmail = False Then
                
                    .Send
                
                End If
            
            End With
    Last edited by And180y; 11-13-2020 at 04:42 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Send excel file as attachment using gmail in macro?
    By fourmurphys in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 10-20-2019, 09:21 PM
  2. Need and macro to send a excel file auto
    By amitkr3855 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-02-2013, 12:34 PM
  3. Macro to Send Copy of Excel file to personal email id.
    By VIJEXCEL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-16-2013, 06:02 AM
  4. change event macro to evaluate windows user who initiated the change then send email
    By pmanoloff in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-23-2012, 03:31 PM
  5. Newbie question; record macro to send excel file as attacment via lotus
    By kkman in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-23-2010, 01:44 PM
  6. How do I change the order of choices in menu File- Send To
    By David McRitchie in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-06-2005, 02:05 PM
  7. How do I change the order of choices in menu File- Send To
    By SCPC7018 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 10:05 AM
  8. How do I change the order of choices in menu File- Send To
    By SCPC7018 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-05-2005, 11:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1