+ Reply to Thread
Results 1 to 5 of 5

Macro. compiling email, attaching 1x sheet + 1x powerpoint file.

Hybrid View

rain4u Macro. compiling email,... 11-24-2011, 08:50 PM
rain4u Re: Macro. compiling email,... 11-26-2011, 09:26 AM
rain4u Re: Macro. compiling email,... 11-27-2011, 01:16 PM
rain4u Re: Macro. compiling email,... 11-27-2011, 09:02 PM
rain4u Re: Macro. compiling email,... 11-28-2011, 02:24 PM
  1. #1
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Macro. compiling email, attaching 1x sheet + 1x powerpoint file.

    Hi all
    I'm using a macro to compile an email. I have used this macro before on some other projects but now I need to make some adjustments and I'm struggling a little bit.


    The main adjustments that I'm trying to achieve are:
    1. Instead copying entire sheet and attach it to the email I only want to copy section of it (named range "Charts_breakdown").
    2. I would also like the macro to copy and rename a PDF file (Statistics.ppt - this file will be open before launching any macro). Macro should rename it as per value of "emailRenamePDFattachment", attach it to the email and kill the Statistics.ppt without saving it.

      I have made some notes on the code. Example spreadsheet is attached. It has a macro button ("Compile EMAIL") to launch the current code. There is also a sheet called "Example of attached sheet" that is simulating the outcome of the sheet that should be attached to the email.


    Global emailTempSaveFolder As String, emailSheetName As String, emailTo As String, emailCC As String, emailSubject As String, emailAttachedFile As String, emailTextBody As String, emailRenamePDFattachment As String
    
    '---vvv-- This part of the code sole purpose is to picking up settings (values in cells) from sheet called "properties email". These will be later used to compile the email tha will later
    Sub EmailVariables_1()
     With ThisWorkbook.Sheets("properties email")
    '---vvv-- Location on of a temporary folder to temporarily save the speadsheet
        emailTempSaveFolder = .Range("B6")
    
    '---vvv-- Name of the sheet that will be copied fully copied over (This is what I would like to change and make obsolete)
        emailSheetName = .Range("C10")
        emailTo = .Range("C11")
        emailCC = .Range("C12")
        emailSubject = .Range("C13")
        emailAttachedFile = .Range("C14")
    '---vvv-- Name of the sheet that will be copied (This is what I would like to only use to name the file that will be attached)
        emailTextBody = .Range("C15") & vbNewLine & vbNewLine & _
                        .Range("C16") & vbNewLine & _
                        .Range("C17") & vbNewLine & _
                        .Range("C18") & vbNewLine & vbNewLine & _
                        .Range("C19") & vbNewLine & vbNewLine & _
                        .Range("C20") & vbNewLine & vbNewLine & vbNewLine & _
                        .Range("C21") & vbNewLine & _
                        .Range("C22")
        emailRenamePDFattachment = .Range("C25")
     End With
    End Sub
    
    
    
    Sub Email_launch_standard_email_1()
     Call EmailVariables_1
        Dim oApp As Object
        Dim oMail As Object
        Dim WB As Workbook
        Dim FileName As String
        Dim wSht As Worksheet
        Dim shtName As String
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
    
    '---vvv-- from this point onwards I'm bit stuck. I would like to change but don't know how.
    'At the moment it copies entire sheet and pastes it to a new file. This will include some charts etc.
        Sheets(emailSheetName).Copy
        Sheets(emailSheetName).UsedRange.Copy
    Range("A1").Select
        Selection.PasteSpecial Paste:=xlPasteValues, _
        Operation:=xlNone, SkipBlanks:=False, Transpose:=False
    'What I would like it to do instead  is to copy named range "Charts_breakdown" (essentially cells A85 to V147),
    'and paste it to the attached sheet cell 1,row 1 downwards. Then I would like the macro to delete row 2 (as it has some dummy data) and autofit all columns.
    '--AAA---------------------------------------------------------
    
    
        Set WB = ActiveWorkbook
        FileName = emailAttachedFile & " " & Format(Now, "dd-mm-yyyy")
        On Error Resume Next
        Kill emailTempSaveFolder & FileName
        On Error GoTo 0
        WB.SaveAs FileName:=emailTempSaveFolder & " " & FileName
        Set oApp = CreateObject("Outlook.Application")
        Set oMail = oApp.CreateItem(0)
        With oMail
        .To = emailTo
        .CC = emailCC
        .Subject = emailSubject & " " & Format(Now, "dd-mm-yyyy")
        .Body = emailTextBody
            .Attachments.Add WB.FullName
            .Display
        End With
        WB.ChangeFileAccess Mode:=xlReadOnly
        Kill WB.FullName
        WB.Close SaveChanges:=False
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Set oMail = Nothing
        Set oApp = Nothing
    
    '---vvv-- From this point onwards I would like the macro to copy PDF file (Statistics.ppt - this file will be open before launching any macro)
    'rename it as per value of "emailRenamePDFattachment", attach it to the email and kill the Statistics.ppt without saving it
    
    End Sub





    Any help would be extremely helpful.
    Cheers
    Attached Files Attached Files
    Last edited by rain4u; 11-28-2011 at 02:24 PM.

  2. #2
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro. compiling email, attaching 1x sheet + 1x PDF file.

    ***bump***

  3. #3
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro. compiling email, attaching 1x sheet + 1x PDF file.

    ***bump***

  4. #4
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro. compiling email, attaching 1x sheet + 1x PDF file.

    I realized that I made a mistake on my post 1. Just to clarify, the file that I'm trying to attach to the email is powerpoint ppt file not PDF as mistakenly stated. My sincere apologizes.

    I have overcome of the problem with problem 1
    1. Instead copying entire sheet and attach it to the email I only want to copy section of it (named range "Charts_breakdown").
    I created a hidden sheet within my workbook where I pre-sorted the sheet to my liking. I no longer need to attach only a partial section of my spreadsheet as I can attach the entire presorted hidden sheet to the email. (for this task my current code works just fine).

    I would still love some help with problem 2.

    Essentially I have powerpoint file called Statistics.ppt which is open before running any macro. I would like the macro to use this powerpoint file and attach it to the email as well. It should rename it as "Weekly statistics" and then todays date (e.g. Weekly Statistics 28-11-2011).


    Any help would be greatly appreciated.
    Cheers

  5. #5
    Forum Contributor
    Join Date
    01-29-2011
    Location
    Bristol, England
    MS-Off Ver
    Excel 2003
    Posts
    471

    Re: Macro. compiling email, attaching 1x sheet + 1x PDF file.

    ***bump***

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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