Insert Image Into Email Body From ClipBoard

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
975
Hi folks,

If I have a file already copied to the clipboard, how do I get that file into the body of an outlook message?

Assuming I already have the file (it's a picture) how would I get it into the body below?

Code:
Sub Email()
    Dim OutApp As Object, OutMail As Object
    Dim Email As String, Center As String
    
    On Error Resume Next
        Set frmCenterLookup.MultiPage1.Pages(2).Picture2 = Clipboard.GetData(vbCFMetaData)
    Err.Clear
    
    On Error GoTo Email_Error
    
    Email = frmCenterLookup.txtDevelopmentManager.Value
    Center = frmCenterLookup.txtCenterConfirm.Value
    
    Set rng = Nothing
    On Error Resume Next

    On Error GoTo 0

    With Application
        .EnableEvents = False
        .ScreenUpdating = False
    End With

    Set OutApp = CreateObject("Outlook.Application")
    Set OutMail = OutApp.CreateItem(0)

    On Error Resume Next
    With OutMail
        .To = Email & "TEST"
        .Subject = "Center " & Center & " Inquiry"
        .HTMLBody = [COLOR="Red"]<--- I need to insert file here[/COLOR]
        .Display

    End With
    On Error GoTo 0

    With Application
        .EnableEvents = True
        .ScreenUpdating = True
    End With

Email_Exit:
    Set OutMail = Nothing
    Set OutApp = Nothing

    On Error GoTo 0
    Exit Sub

Email_Error:

    MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure Email of Module EmailCode"
    Err.Clear
    GoTo Email_Exit

End Sub
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
You can't do anything with it from the Clipboard as far as I'm aware... no, I'm fairly sure that's not possible.

But if you have an image file on disk, you can use the HTML IMG tag to insert it into the body of your message. Something like this:-
Code:
.HTMLBody="< img src='C:\Temp\logo.jpg'>"

(Remove the space after the < character.)
 
Upvote 0
How did the image get into the Clipboard? Perhaps there's some way...
 
Upvote 0
Google suggests fairly strongly you can't access images in the Clipboard object in VBA, although they are accessible from VB/VB.Net. I don't know this as a fact - I'm taking the word of the majority. (Accessing text in the Clipboard is possible in VBA though.)

If you're desperate, someone has posted a DLL which gives you access to the Clipboard but obviously it will need to be installed on every machine which needs to run the code: http://www.vbforums.com/showthread.php?t=608372.

You would have to save the contents of the Clipboard to disk and then use an IMG tag to include it in your .HTMLBody.
<!--EndFragment -->
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,651
Messages
6,120,744
Members
448,989
Latest member
mariah3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top