UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Paste Clipboard Image Into VBA Outlook Html, Access 2010    
 
   
BigPaul
post Nov 3 2017, 07:37 AM
Post#1



Posts: 32
Joined: 20-November 04
From: Colchester, UK


I have a form with a button to send HTML mail.
I copy part of the form (set up with relevant data) to the clipboard.
I hit the email button which formats the email, drags fields in, then opens the Outlook email in .display mode
I manually paste the clipboard into the middle of the email and manually send it.

What I would like to do is automate the pasting so
I copy part of the form to the clipboard.
I hit the email button which send the formatted email with the pasted image in the middle.

I've played with GetFromClipboard but cannot find the syntax to paste image (it tries to paste as text I think)

The following is error free BUT the image is simply a blank space it is not the content (or related to the size of the cut image) of the clipboard.

Here the code I have used to date (please feel free to completely re-write :-) )

Any help gratefully accepted.


CODE
Private Sub cmdFailureEmail_Click()
'Send Email using late binding to avoid reference issues
'  ** This code contains a Clipboard PASTE option which requires;  Microsoft Forms 2.0 Object Library
    Dim objOutlook As Object
    Dim objOutlookMsg As Object
    Dim objOutlookRecip As Object
    Dim objOutlookAttach As Object
    Const olMailItem = 0

    'Following collects the clipboard data
    Dim MyData As DataObject
    Set MyData = New DataObject
    MyData.GetFromClipboard
    On Error Resume Next    'The .GetFromClipboard method fails when the clipboard is empty.
    ' use it thus;  MyData.GetText(1)

    Set objOutlook = CreateObject("Outlook.Application")
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg

        Set objOutlookRecip = .Recipients.Add("someone@somwhere.com")
        objOutlookRecip.Type = 1

        Dim txtBody As String

        'Set the body

        txtBody = "<html>" & vbNewLine

        '--- Start the Head ---

        txtBody = txtBody & "<head>" & vbNewLine
        txtBody = txtBody & "<style>" & vbNewLine    ' Start the Style block
        txtBody = txtBody & " body,pre{font family:Arial; font-size:10pt; color:#666;}" & vbNewLine    ' Set the body and sig styles font
        txtBody = txtBody & " table {width:610px;}" & vbNewLine    ' Set the table style width
        txtBody = txtBody & " .content{margin:10px;}" & vbNewLine    ' Set the class for the main content for a margin
        txtBody = txtBody & "</style>" & vbNewLine    ' Close the Style block
        txtBody = txtBody & "</head>" & vbNewLine

        '### End the Head ###

        txtBody = txtBody & "<p>Salutation,</p>" & vbNewLine
        txtBody = txtBody & "<p>Preamble text</p>" & vbNewLine
        txtBody = txtBody & "<p>Action text</p>" & vbNewLine
        txtBody = txtBody & "<p><img src=""" & MyData.GetText(1) & """></p>" & vbNewLine                      '<<< This is the attempt to paste the clipboard
        txtBody = txtBody & "<p>&nbsp</p>" & vbNewLine    'blank line
        txtBody = txtBody & "<p>Please let us all know when this has been completed. </p>" & vbNewLine
        txtBody = txtBody & "<p>Regards</p>" & vbNewLine


        .CC = "somebodyelse@somewhere.com"
        .Subject = "Header built from fields on the form"
        .HTMLBody = txtBody
        .Importance = 1    'Importance Level  0=Low,1=Normal,2=High

        .Display

    End With

    'Tidy Up

    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing
    Set objOutlookRecip = Nothing
    Set objOutlookAttach = Nothing
    Set MyData = Nothing
End Sub
Go to the top of the page
 
DanielPineault
post Nov 3 2017, 08:28 AM
Post#2


UtterAccess VIP
Posts: 5,454
Joined: 30-June 11



Personally, whenever I've used images in e-mail, I save the image (to the temp folder or a working folder), the reference it in the src ... and cleanup by deleting the image once I'm done.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 
Doug Steele
post Nov 3 2017, 09:19 AM
Post#3


UtterAccess VIP
Posts: 21,498
Joined: 8-January 07
From: St. Catharines, ON (Canada)


My question would be what is MyData.GetText(1) returning?

Take a look at The <img src=””> HTML Tag, where it says
QUOTE
The src attribute identifies an image by a URL. The image defined by the URL is retrieved by the browser and inserted into the document when the page loads.

Then look at the section on Data URIs. Is that what you're writing?

--------------------
Go to the top of the page
 
BigPaul
post Nov 4 2017, 07:58 AM
Post#4



Posts: 32
Joined: 20-November 04
From: Colchester, UK


Thanks Daniel, I had thought of that, but hoped there was a direct way. I will try your solution on Monday, thanks PAUL

Thanks to the other contributors as well
Go to the top of the page
 
DanielPineault
post Nov 4 2017, 09:03 PM
Post#5


UtterAccess VIP
Posts: 5,454
Joined: 30-June 11



We're all glad to help. Post back if you need any further assistance.

--------------------
Daniel Pineault (2010-2017 Microsoft MVP)
Professional Help: http://www.cardaconsultants.com
Free MS Access Code, Tips, Tricks and Samples: http://www.devhut.net

* Design should never say "Look at me". It should always say "Look at this". -- David Craib
* A user interface is like a joke, if you have to explain it, it's not that good! -- Martin LeBlanc


All code samples, demonstration databases, links,... are provided 'AS IS' and are to be used at your own risk! Take the necessary steps to check, validate ...
Go to the top of the page
 


Custom Search
RSSSearch   Top   Lo-Fi    17th December 2017 - 10:23 PM