+ Reply to Thread
Results 1 to 7 of 7

Need Help with Macro extracting data to Email

Hybrid View

  1. #1
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Need Help with Macro extracting data to Email

    Hi Guys

    I have a macro running that will detach a current worksheet from a workbook and attach it to an email. What im looking to do is use the same code to extract a specific cell range within that worksheet to an email attachment instead, anyone have any ideas?

    VBA Code... Any help would be much appreciated guys!
    Sub EmailNewBuildProject()
         'Variable declaration
        Dim oApp As Object, _
        oMail As Object, _
        WB As Workbook, _
        FileName As String
         
         'Turn off screen updating
        Application.ScreenUpdating = False
         
         'Make a copy of the active sheet and save it to
         'a temporary file
        ActiveSheet.Copy
        Set WB = ActiveWorkbook
        FileName = "New Build Project.xls"
        On Error Resume Next
        Kill "H:\" & FileName
        On Error GoTo 0
        WB.SaveAs FileName:="H:\" & FileName
         
         'Create and show the outlook mail item
        Set oApp = CreateObject("Outlook.Application")
        Set oMail = oApp.CreateItem(0)
        With oMail
             'Uncomment the line below to hard code a recipient
             '.To = "[email protected]"
             'Uncomment the line below to hard code a subject
             .Subject = "New Build Project Template"
            .Attachments.Add WB.FullName
            .Display
        End With
         
         'Delete the temporary file
        WB.ChangeFileAccess Mode:=xlReadOnly
        Kill WB.FullName
        WB.Close SaveChanges:=False
         
         'Restore screen updating and release Outlook
        Application.ScreenUpdating = True
        Set oMail = Nothing
        Set oApp = Nothing
    End Sub
    Last edited by weesteev; 02-08-2012 at 04:28 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,914

    Re: Need Help with Macro extracting data to Email

    Have you looked at Ron de Bruin's site? He covers pretty much everything.

    Note that ...

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # at the top of your post window. For more information about these and other tags, found here
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: Need Help with Macro extracting data to Email

    Thanks Shucks, have amended post now.

    I have had a look at Ron's site and where he does have good info about hiding images and groups, he doesnt mention anything about exporting only a set range. In the example above I would want to incorporate something that extracted cells A1 to M44 only, any ideas how I can incorporate this?

    Cheers

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,914

    Re: Need Help with Macro extracting data to Email

    Thanks for the rep.

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,914

    Re: Need Help with Macro extracting data to Email

    This page has a variety of examples for sending a range using SendMail, Outlook, whatever.

    http://www.rondebruin.nl/sendmail.htm


    Regards, TMS

  6. #6
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: Need Help with Macro extracting data to Email

    Thanks TMSucks, have tried both the "selection" and "range" options, and while they both extract the data perfectly I have found another issue! How would it be possible to extract any cell data as well as images within that range? Currently the macro ignores all images and only exports Text data. Any Ideas?

    Cheers

  7. #7
    Registered User
    Join Date
    07-08-2008
    Location
    UK
    Posts
    10

    Re: Need Help with Macro extracting data to Email

    Not completely solved yet, hopefully someone can help with my images quandary

+ 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