+ Reply to Thread
Results 1 to 2 of 2

Marco/VBA to copy a selection and paste into an email as a picture

  1. #1
    Forum Contributor
    Join Date
    08-22-2013
    Location
    Sheffield
    MS-Off Ver
    Excel 2010
    Posts
    161

    Lightbulb Marco/VBA to copy a selection and paste into an email as a picture

    Morning all,

    I've been trying to do this for a couple of days with no joy. I currently have a spreadsheet that opens outlook and autofills everything that i require.

    It also selects the area that i would want to paste into the body of the email as a picture automatically once the button is pressed.

    Please Login or Register  to view this content.
    Any help on this matter would be great!

    Thanks

  2. #2
    Registered User
    Join Date
    02-27-2012
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    77

    Re: Marco/VBA to copy a selection and paste into an email as a picture

    Try this, and specify the range that you want to copy in "'Publish the sheet to a htm file" area.

    Dim fso As Object
    Dim ts As Object
    Dim TempFile As String
    Dim TempWB As Workbook

    TempFile = Environ$("temp") & "/" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"

    'Copy the range and create a new workbook to past the data in
    rng.Copy
    Set TempWB = Workbooks.Add(1)
    With TempWB.Sheets(1)
    .Cells(1).PasteSpecial Paste:=8
    .Cells(1).PasteSpecial xlPasteValues, , False, False
    .Cells(1).PasteSpecial xlPasteFormats, , False, False
    .Cells(1).Select
    Application.CutCopyMode = False
    On Error Resume Next
    .DrawingObjects.Visible = True
    .DrawingObjects.Delete
    On Error GoTo 0
    End With

    'Publish the sheet to a htm file
    With TempWB.PublishObjects.Add( _
    SourceType:=xlSourceRange, _
    Filename:=TempFile, _
    Sheet:=TempWB.Sheets(1).Name, _
    Source:=TempWB.Sheets(1).UsedRange.Address, _
    HtmlType:=xlHtmlStatic)
    .Publish (True)
    End With

    'Read all data from the htm file into RangetoHTML
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
    RangetoHTML = ts.ReadAll
    ts.Close
    RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
    "align=left x:publishsource=")

    'Close TempWB
    TempWB.Close savechanges:=False

    'Delete the htm file we used in this function
    Kill TempFile

    Set ts = Nothing
    Set fso = Nothing
    Set TempWB = Nothing

+ 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. Copy and paste Excel range as picture into Outlook email body using excel vba
    By ExcelDoc in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 01-17-2016, 09:29 PM
  2. Copy and Paste Marco
    By Groves29 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-07-2013, 10:11 AM
  3. [SOLVED] Help with Looping a copy and paste marco
    By Robert110 in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 03-26-2013, 11:02 AM
  4. Replies: 3
    Last Post: 02-20-2006, 12:55 PM
  5. macro to copy selection and paste special as picture in word
    By rabbi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-03-2005, 09:29 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