Solved

Embed a .jpg picture in an email with VBA - truble passing from Outlook 2000 to 2003.

Posted on 2008-06-25
4
2,304 Views
Last Modified: 2013-11-27
Hi I have developed a simple function that work perfectly with Access-Outlook 2000, but not with Access 2000-Outlook 2003.
It does everything but does not embed the image I would insert in preview with the line:
oHTML = "<HTML><Head></Head><Body><img SRC='" & oLettera & "' width=800 height=1130></Body></HTML>"
I have tried to insert CID parameters and other stuff, but with no result. Can you help, please?
Public Function InviaOutlookMailCampagne(oDestinatario As String, oOggetto As String, oLettera As String, oAllegato As String)
 
    Dim olkApp As Object, olkMsg As Object
    Dim oFile As String
    Dim oHTML As String
    Set olkApp = GetObject(, "Outlook.Application")
    '
    Set olkMsg = olkApp.CreateItemFromTemplate("L:\9.1.Campagne\Lettere\Modello emailing.oft")
    
    oHTML = "<HTML><Head></Head><Body><img SRC='" & oLettera & "' width=800 height=1130></Body></HTML>"
    
    With olkMsg
            .To = oDestinatario
            .Subject = oOggetto
            .HTMLBody = oHTML
            '.body = oMessaggio
            '.Attachments.Add oLettera
            .Attachments.Add oAllegato
            .Save
    End With
    '
    Set olkMsg = Nothing
    Set olkApp = Nothing
    '
 
End Function

Open in new window

0
Comment
Question by:Sar1973
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 21939353
Sar1973,

Try this code.
It is straight from the MS website.

It works fine for me.

Please verify that it works "As Is".
Then try to adapt it to work in your Application.

You must set a reference to the Outlook Object Library in your VBA Editor.

JeffCoachman

Sub sbSendMessage()
Dim objOutlook                  As Outlook.Application
Dim objOutlookMsg               As Outlook.MailItem
Dim objOutlookRecip             As Outlook.Recipient
Dim objOutlookAttach            As Outlook.Attachment
 
 
' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
    With objOutlookMsg
        ' Add the To recipient(s) to the message. Substitute
        ' your names here.
        Set objOutlookRecip = .Recipients.Add("Recipient Name")   '<--Recipient's name or email address
        objOutlookRecip.Type = olTo
        ' Add the CC recipient(s) to the message.
        'Set objOutlookRecip = .Recipients.Add("CC Recipient Name")
        'objOutlookRecip.Type = olCC
        ' Set the Subject, Body, and Importance of the message.
        .Subject = "This is an Automation test with Microsoft Outlook"      '<--Subject
        '.Body = "This is normal Text in the Body of the email"              '<--Email Body text.
        'Use this to send the Email using the HTML Format
        '.HTMLBODY = "<HTML><H2><b>This is HTML Text in the BODY of the email</b></H2></HTML>"
        .HTMLBODY = "<HTML><Head></Head><Body><img SRC=c:\earth.jpg></Body></HTML>"
 
        .Importance = olImportanceHigh  'High importance
        'Add attachments to the message.
        'Set objOutlookAttach = .Attachments.Add("C:\Earth.jpg")             '<-- Add as many attachments as you need here.
        'Set objOutlookAttach = .Attachments.Add("C:\TextFile.txt")
        
        ' Resolve each Recipient's name.
        For Each objOutlookRecip In .Recipients
            If Not objOutlookRecip.Resolve Then
                objOutlookMsg.Display
            End If
        Next
        
        'Send email without viewing it.
        '.Send
        
        'Dispay email before sending.
        .Display
    
    End With
 
'Cleanup Code
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
Set objOutlookRecip = Nothing
Set objOutlookAttach = Nothing
 
End Sub

Open in new window

0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 21939355
Of course change the HTLM and add your own image and path.
0
 
LVL 9

Author Comment

by:Sar1973
ID: 21940849
Definitely, the syntax is <img SRC=C:\File.jpg> and not <img SRC='C:\File.jpg'> ...?
0
 
LVL 74

Accepted Solution

by:
Jeffrey Coachman earned 75 total points
ID: 21941985
Sar1973,

<img SRC=C:\File.jpg>
... worked fine for me.

As I said, test it out to be sure.

JeffCoachman
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I set my Access Query up to filter out specific records 13 53
ListData refresh onClick 5 40
Form performance table vs. query 27 61
SUBFORM on ACCESS 2013 8 24
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question