+ Reply to Thread
Results 1 to 3 of 3

Macro for saving sheet as PDF to desktop and attach to email

Hybrid View

  1. #1
    Registered User
    Join Date
    12-04-2015
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2011 for mac
    Posts
    24

    Macro for saving sheet as PDF to desktop and attach to email

    Hi guys,
    I have never written a macro before, only recorded them. By recording the macro I can only get the sheet to save as PDF not attach to email. What i'm trying to do is: I have a sheet called "Exchange Sheet". I need a macro that will safe this sheet to my desktop as a PDF (with the same name "Exchange sheet") then attach it to an outlook email. I would then just manually enter email address and email text.

    Any help would be greatly appreciated.

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,015

    Re: Macro for saving sheet as PDF to desktop and attach to email

    .
    This works on a PC .. not certain about a Mac :

    Option Explicit
    
    
    Sub test()
    Dim TempWB As Workbook
    Dim fd As String
    Application.DisplayAlerts = False
    Application.ScreenUpdating = False
    ActiveSheet.Copy
    Set TempWB = ActiveWorkbook
    
    fd = "C:\Users\My\Desktop"   'Edit path as required. Assumes the folder Test already exists on the desktop
    'fd now holds the path to the folder
      
    With TempWB
    'Exchange Sheet is the name of the saved CSV file. Edit name as required.
        .SaveAs Filename:=fd & "\Exchange_Sheet", FileFormat:=xlCSVWindows, CreateBackup:=False
        .Close
    End With
    
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    
    Email_Sheet
    
    End Sub
    
    Sub Email_Sheet()
    
       Dim oApp As Object
       Dim oMail As Object
       Dim CSVSheet As String
    
       'Turn off screen updating
       Application.ScreenUpdating = False
    
       'Copy the active worksheet and save to a temporary workbook
       'ActiveSheet.Copy
       CSVSheet = "C:\Users\My\Desktop\Exchange_Sheet.csv"
    
       'Create a temporary file in your current directory that uses the name
       ' of the sheet as the filename
       'LFileName = LWorkbook.Worksheets(1).Name
       On Error Resume Next
       'Delete the file if it already exists
       'Kill LFileName
       On Error GoTo 0
       'Save temporary file
       'LWorkbook.SaveAs Filename:=LFileName
    
       'Create an Outlook object and new mail message
       Set oApp = CreateObject("Outlook.Application")
       Set oMail = oApp.CreateItem(0)
    
       'Set mail attributes (uncomment lines to enter attributes)
       ' In this example, only the attachment is being added to the mail message
       With oMail
          .To = ""
          .Subject = ""
          .body = ""
          .Attachments.Add CSVSheet
          .Display
       End With
    
       'Turn back on screen updating
       Application.ScreenUpdating = True
       Set oMail = Nothing
       Set oApp = Nothing
    
    End Sub
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    12-04-2015
    Location
    Edinburgh, Scotland
    MS-Off Ver
    2011 for mac
    Posts
    24

    Re: Macro for saving sheet as PDF to desktop and attach to email

    Logit,
    thanks for your reply. Its for a PC in my work (just got the Mac at home). I will give it a go in the morning when back to work. Thanks again

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Saving to user desktop using a Macro
    By Werewindle in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-19-2014, 04:43 PM
  2. Macro to attach range to email in new sheet but not send?
    By Serafin54 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-22-2014, 01:07 PM
  3. attach different worksheet and email them tdifferent email address through macro/vba/addin
    By arunverma004 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-03-2014, 08:20 AM
  4. [SOLVED] Email Macro to attach a non active worksheet to outlook email
    By mickgibbons1 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-21-2013, 08:38 PM
  5. [SOLVED] Saving to Desktop Macro
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-05-2013, 07:39 AM
  6. SaveAs PDF and attach to email macro won't attach?!
    By Rerock in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2012, 05:28 PM
  7. macro to email only active sheet as PDF attach
    By ChrisCPA7 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-17-2012, 04:45 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