A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

newbie creating email VBA question



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old December 20th 06, 06:40 PM posted to microsoft.public.outlook.program_vba
Keith
external usenet poster
 
Posts: 8
Default newbie creating email VBA question

I'm using Office 2003 on WinXP.

I have several gif files that I create in Excel (from Excel ranges) and
within Excel, I want to create an email that attaches these GIF files and
sends them to the target recipient. I have this working (in theory) when
sending to myself, but there are a few things not working properly, and I'm
hoping someone here can help- even though the code below is run from Excel,
folks here are more likely to be able to spot syntax issues related to the
code that manipulates Outlook.

Goal: to have the images show up inline, e.g. visible when the email is
opened (currently it shows up as an attached file that then needs to be
opened). My default outlook email editor is Word2003, and I can do this by
creating a new email, and inserting an image:

Selection.InlineShapes.AddPicture FileName:="C:\AEPARDAV1.gif", LinkToFile _
:=False, SaveWithDocument:=True

However, I'm not sure that Word is part of the equation when I run my code
directly from Excel:

Function Mail_Selection_Range_Outlook_Body(SendToName As String,
SendFileCount As Integer)
' code adapted from http://www.rondebruin.nl/mail/
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

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

FName = "c:\" & SendToName
FExt = ".gif"

On Error Resume Next
With OutMail
.To = "rucksk" 'SendToName
.CC = ""
.BCC = ""
.Subject = "Roadblocks data update request"
.Body.Add = "Please respond to this email, and include comments and
updates directly under each row"
'.Body.Add = Chr(13)
For n = 1 To SendFileCount
.Attachments.Add (FName & CStr(n) & FExt) ' this is where it adds as
an attachment instead of inline
'.Body.Add = Chr(13)
Next
.Send 'or use .Display
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
End Function


Ads
  #2  
Old December 20th 06, 07:15 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default newbie creating email VBA question

Very important question: Is WordMail your Outlook editor? If not, you can't use Word methods. If it is, then use Outlook's Inspector.WordEditor method to return a Word.Document object that you can then use with methods like AddPicture, e.g.:

strFile = "C:\AEPARDAV1.gif"
Set objInsp = OutMail.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection
If objMsg.BodyFormat olFormatPlain Then
objSel.InlineShapes.AddPicture strFile, False, True
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Keith" wrote in message ...
I'm using Office 2003 on WinXP.

I have several gif files that I create in Excel (from Excel ranges) and
within Excel, I want to create an email that attaches these GIF files and
sends them to the target recipient. I have this working (in theory) when
sending to myself, but there are a few things not working properly, and I'm
hoping someone here can help- even though the code below is run from Excel,
folks here are more likely to be able to spot syntax issues related to the
code that manipulates Outlook.

Goal: to have the images show up inline, e.g. visible when the email is
opened (currently it shows up as an attached file that then needs to be
opened). My default outlook email editor is Word2003, and I can do this by
creating a new email, and inserting an image:

Selection.InlineShapes.AddPicture FileName:="C:\AEPARDAV1.gif", LinkToFile _
:=False, SaveWithDocument:=True

However, I'm not sure that Word is part of the equation when I run my code
directly from Excel:

Function Mail_Selection_Range_Outlook_Body(SendToName As String,
SendFileCount As Integer)
' code adapted from http://www.rondebruin.nl/mail/
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

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

FName = "c:\" & SendToName
FExt = ".gif"

On Error Resume Next
With OutMail
.To = "rucksk" 'SendToName
.CC = ""
.BCC = ""
.Subject = "Roadblocks data update request"
.Body.Add = "Please respond to this email, and include comments and
updates directly under each row"
'.Body.Add = Chr(13)
For n = 1 To SendFileCount
.Attachments.Add (FName & CStr(n) & FExt) ' this is where it adds as
an attachment instead of inline
'.Body.Add = Chr(13)
Next
.Send 'or use .Display
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
End Function


  #3  
Old December 20th 06, 07:57 PM posted to microsoft.public.outlook.program_vba
Keith
external usenet poster
 
Posts: 8
Default newbie creating email VBA question

Sue-

Thank you for your response. My preference would be to use code that is
independent of the default editor (e.g. limit it to Outlook only- I'm not
sure if this is possible?), as the workbook will be maintained by a support
team, and I don't have control over what they use for their editor- some may
use Word, some may not. I copied over the Word code just to show what (on my
machine, anyway) was able to generate the desired result- but it may not be
the desired way to reach that result.

If there is a way to attach inline images directly without referencing Word,
that would be preferable- even if I wrote conditional code to determine if
Word is the editor for whoever is using the file, the best I could do is
kill the macro, because I'd want to avoid sending emails with the images as
attachments.

Perhaps there is a parameter of Attachments.Add, or a way to add a graphic
file as part of the mail body?

Many thanks,
Keith



"Sue Mosher [MVP-Outlook]" wrote in message
...
Very important question: Is WordMail your Outlook editor? If not, you can't
use Word methods. If it is, then use Outlook's Inspector.WordEditor method
to return a Word.Document object that you can then use with methods like
AddPicture, e.g.:

strFile = "C:\AEPARDAV1.gif"
Set objInsp = OutMail.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection
If objMsg.BodyFormat olFormatPlain Then
objSel.InlineShapes.AddPicture strFile, False, True
End If

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Keith" wrote in message
...
I'm using Office 2003 on WinXP.

I have several gif files that I create in Excel (from Excel ranges) and
within Excel, I want to create an email that attaches these GIF files and
sends them to the target recipient. I have this working (in theory) when
sending to myself, but there are a few things not working properly, and
I'm
hoping someone here can help- even though the code below is run from
Excel,
folks here are more likely to be able to spot syntax issues related to the
code that manipulates Outlook.

Goal: to have the images show up inline, e.g. visible when the email is
opened (currently it shows up as an attached file that then needs to be
opened). My default outlook email editor is Word2003, and I can do this by
creating a new email, and inserting an image:

Selection.InlineShapes.AddPicture FileName:="C:\AEPARDAV1.gif", LinkToFile
_
:=False, SaveWithDocument:=True

However, I'm not sure that Word is part of the equation when I run my code
directly from Excel:

Function Mail_Selection_Range_Outlook_Body(SendToName As String,
SendFileCount As Integer)
' code adapted from http://www.rondebruin.nl/mail/
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

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

FName = "c:\" & SendToName
FExt = ".gif"

On Error Resume Next
With OutMail
.To = "rucksk" 'SendToName
.CC = ""
.BCC = ""
.Subject = "Roadblocks data update request"
.Body.Add = "Please respond to this email, and include comments and
updates directly under each row"
'.Body.Add = Chr(13)
For n = 1 To SendFileCount
.Attachments.Add (FName & CStr(n) & FExt) ' this is where it adds
as
an attachment instead of inline
'.Body.Add = Chr(13)
Next
.Send 'or use .Display
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
End Function




  #4  
Old December 20th 06, 08:16 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default newbie creating email VBA question

There is another method, but it requires CDO, which is an optional component, or Redemption, a third-party component, and is quite a bit more complex. See http://www.outlookcode.com/d/code/htmlimg.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Keith" wrote in message ...
Sue-

Thank you for your response. My preference would be to use code that is
independent of the default editor (e.g. limit it to Outlook only- I'm not
sure if this is possible?), as the workbook will be maintained by a support
team, and I don't have control over what they use for their editor- some may
use Word, some may not. I copied over the Word code just to show what (on my
machine, anyway) was able to generate the desired result- but it may not be
the desired way to reach that result.

If there is a way to attach inline images directly without referencing Word,
that would be preferable- even if I wrote conditional code to determine if
Word is the editor for whoever is using the file, the best I could do is
kill the macro, because I'd want to avoid sending emails with the images as
attachments.

Perhaps there is a parameter of Attachments.Add, or a way to add a graphic
file as part of the mail body?

Many thanks,
Keith



"Sue Mosher [MVP-Outlook]" wrote in message
...
Very important question: Is WordMail your Outlook editor? If not, you can't
use Word methods. If it is, then use Outlook's Inspector.WordEditor method
to return a Word.Document object that you can then use with methods like
AddPicture, e.g.:

strFile = "C:\AEPARDAV1.gif"
Set objInsp = OutMail.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection
If objMsg.BodyFormat olFormatPlain Then
objSel.InlineShapes.AddPicture strFile, False, True
End If



"Keith" wrote in message
...
I'm using Office 2003 on WinXP.

I have several gif files that I create in Excel (from Excel ranges) and
within Excel, I want to create an email that attaches these GIF files and
sends them to the target recipient. I have this working (in theory) when
sending to myself, but there are a few things not working properly, and
I'm
hoping someone here can help- even though the code below is run from
Excel,
folks here are more likely to be able to spot syntax issues related to the
code that manipulates Outlook.

Goal: to have the images show up inline, e.g. visible when the email is
opened (currently it shows up as an attached file that then needs to be
opened). My default outlook email editor is Word2003, and I can do this by
creating a new email, and inserting an image:

Selection.InlineShapes.AddPicture FileName:="C:\AEPARDAV1.gif", LinkToFile
_
:=False, SaveWithDocument:=True

However, I'm not sure that Word is part of the equation when I run my code
directly from Excel:

Function Mail_Selection_Range_Outlook_Body(SendToName As String,
SendFileCount As Integer)
' code adapted from http://www.rondebruin.nl/mail/
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

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

FName = "c:\" & SendToName
FExt = ".gif"

On Error Resume Next
With OutMail
.To = "rucksk" 'SendToName
.CC = ""
.BCC = ""
.Subject = "Roadblocks data update request"
.Body.Add = "Please respond to this email, and include comments and
updates directly under each row"
'.Body.Add = Chr(13)
For n = 1 To SendFileCount
.Attachments.Add (FName & CStr(n) & FExt) ' this is where it adds
as
an attachment instead of inline
'.Body.Add = Chr(13)
Next
.Send 'or use .Display
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
End Function




  #5  
Old December 20th 06, 08:40 PM posted to microsoft.public.outlook.program_vba
Keith
external usenet poster
 
Posts: 8
Default newbie creating email VBA question

Wow, I wouldn't have been able to tackle this on my own, but with the code
snippet you reference, I'll try to make sure I understand it, then adapt it
and see if I can get it to work.
Many, many thanks!!
Keith

"Sue Mosher [MVP-Outlook]" wrote in message
...
There is another method, but it requires CDO, which is an optional
component, or Redemption, a third-party component, and is quite a bit more
complex. See http://www.outlookcode.com/d/code/htmlimg.htm

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Keith" wrote in message
...
Sue-

Thank you for your response. My preference would be to use code that is
independent of the default editor (e.g. limit it to Outlook only- I'm not
sure if this is possible?), as the workbook will be maintained by a
support
team, and I don't have control over what they use for their editor- some
may
use Word, some may not. I copied over the Word code just to show what (on
my
machine, anyway) was able to generate the desired result- but it may not
be
the desired way to reach that result.

If there is a way to attach inline images directly without referencing
Word,
that would be preferable- even if I wrote conditional code to determine if
Word is the editor for whoever is using the file, the best I could do is
kill the macro, because I'd want to avoid sending emails with the images
as
attachments.

Perhaps there is a parameter of Attachments.Add, or a way to add a graphic
file as part of the mail body?

Many thanks,
Keith



"Sue Mosher [MVP-Outlook]" wrote in message
...
Very important question: Is WordMail your Outlook editor? If not, you
can't
use Word methods. If it is, then use Outlook's Inspector.WordEditor method
to return a Word.Document object that you can then use with methods like
AddPicture, e.g.:

strFile = "C:\AEPARDAV1.gif"
Set objInsp = OutMail.GetInspector
Set objDoc = objInsp.WordEditor
Set objWord = objDoc.Application
Set objSel = objWord.Selection
If objMsg.BodyFormat olFormatPlain Then
objSel.InlineShapes.AddPicture strFile, False, True
End If



"Keith" wrote in message
...
I'm using Office 2003 on WinXP.

I have several gif files that I create in Excel (from Excel ranges) and
within Excel, I want to create an email that attaches these GIF files and
sends them to the target recipient. I have this working (in theory) when
sending to myself, but there are a few things not working properly, and
I'm
hoping someone here can help- even though the code below is run from
Excel,
folks here are more likely to be able to spot syntax issues related to
the
code that manipulates Outlook.

Goal: to have the images show up inline, e.g. visible when the email is
opened (currently it shows up as an attached file that then needs to be
opened). My default outlook email editor is Word2003, and I can do this
by
creating a new email, and inserting an image:

Selection.InlineShapes.AddPicture FileName:="C:\AEPARDAV1.gif",
LinkToFile
_
:=False, SaveWithDocument:=True

However, I'm not sure that Word is part of the equation when I run my
code
directly from Excel:

Function Mail_Selection_Range_Outlook_Body(SendToName As String,
SendFileCount As Integer)
' code adapted from http://www.rondebruin.nl/mail/
' Don't forget to copy the function RangetoHTML in the module.
' Working in Office 2000-2007

Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object

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

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

FName = "c:\" & SendToName
FExt = ".gif"

On Error Resume Next
With OutMail
.To = "rucksk" 'SendToName
.CC = ""
.BCC = ""
.Subject = "Roadblocks data update request"
.Body.Add = "Please respond to this email, and include comments
and
updates directly under each row"
'.Body.Add = Chr(13)
For n = 1 To SendFileCount
.Attachments.Add (FName & CStr(n) & FExt) ' this is where it adds
as
an attachment instead of inline
'.Body.Add = Chr(13)
Next
.Send 'or use .Display
End With
On Error GoTo 0

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

Set OutMail = Nothing
Set OutApp = Nothing
End Function






  #6  
Old December 21st 06, 09:47 PM posted to microsoft.public.outlook.program_vba
Keith
external usenet poster
 
Posts: 8
Default newbie creating email VBA question

Sue (and others)-

I've tried to adapt the code provided below, and have been very impressed
once I figured out how to get it integrated with my code that cycles through
to create the individual emails. I now have two challenges that I think are
both easy for someone who knows Outlook (e.g. not me);

- using the following code doesn't set a recipient, but I think I can do
that with some variation of:
l_Msg.to = SendToName

I'll often have more than one attachment (see the loop below) and only the
first one gets translated into an in-line image instead of an attachment.
I'd also like to insert a carriage return (or two) between each image, so it
is easy for the recipient to reply and have space to type between the images
in their response. I've marked the relevant parts of code with ** below

I'd also like to set a recipient, but I think I can do that with some
variation of:
l_Msg.to = SendToName

Many thanks,
Keith

"Sue Mosher [MVP-Outlook]" wrote in message
...
There is another method, but it requires CDO, which is an optional
component, or Redemption, a third-party component, and is quite a bit more
complex. See http://www.outlookcode.com/d/code/htmlimg.htm


My slightly adapted code, based on the referenced web page:

Function EmbeddedHTMLGraphicDemo(SendToName As String, SendFileCount As
Integer)
' adapted from http://www.outlookcode.com/d/code/htmlimg.htm
' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field

Dim strEntryID As String

' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments

FName = "c:\" & SendToName
FExt = ".gif"

'loop to add each graphical file
For n = 1 To SendFileCount
Set l_Attach = colAttach.Add(FName & CStr(n) & FExt)
'** how can I add (inline) a few hard returns here? **
Next

l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' POSITION CRITICAL you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing

' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False

' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an IMG tag
Set oAttachs = oMsg.Attachments

' ** to make all images inline- should I just loop and assume they are all
1 to SendFileCount? **
' ** I don't understand what this block does :-/ **
'e.g.
'For q = 1 to SendFileCount
'Set oAttach = oAttachs.Item(q)
'Set colFields = oAttach.Fields
'Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
'Set oField = colFields.Add(&H3712001E, "myident")
'oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
'next q

'existing code that only changes the first attachment
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update

' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntry ID)
' add HTML content -- the IMG tag
l_Msg.HTMLBody = "IMG align=baseline border=0 hspace=0 src=cid:myident"
l_Msg.Close (olSave)
l_Msg.Display

' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing
End Function


  #7  
Old December 27th 06, 01:13 PM posted to microsoft.public.outlook.program_vba
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: 11,651
Default newbie creating email VBA question

I'll often have more than one attachment (see the loop below) and only the
first one gets translated into an in-line image instead of an attachment.


You'd need to give each attachment its own unique identifier in the &H3712001E field, not use "myident" for every one.

I'd also like to insert a carriage return (or two) between each image


Use br or p/p HTML tags.
--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx

"Keith" wrote in message ...
Sue (and others)-

I've tried to adapt the code provided below, and have been very impressed
once I figured out how to get it integrated with my code that cycles through
to create the individual emails. I now have two challenges that I think are
both easy for someone who knows Outlook (e.g. not me);

- using the following code doesn't set a recipient, but I think I can do
that with some variation of:
l_Msg.to = SendToName

I'll often have more than one attachment (see the loop below) and only the
first one gets translated into an in-line image instead of an attachment.
I'd also like to insert a carriage return (or two) between each image, so it
is easy for the recipient to reply and have space to type between the images
in their response. I've marked the relevant parts of code with ** below

I'd also like to set a recipient, but I think I can do that with some
variation of:
l_Msg.to = SendToName

Many thanks,
Keith

"Sue Mosher [MVP-Outlook]" wrote in message
...
There is another method, but it requires CDO, which is an optional
component, or Redemption, a third-party component, and is quite a bit more
complex. See http://www.outlookcode.com/d/code/htmlimg.htm


My slightly adapted code, based on the referenced web page:

Function EmbeddedHTMLGraphicDemo(SendToName As String, SendFileCount As
Integer)
' adapted from http://www.outlookcode.com/d/code/htmlimg.htm
' Outlook objects
Dim objApp As Outlook.Application
Dim l_Msg As MailItem
Dim colAttach As Outlook.Attachments
Dim l_Attach As Outlook.Attachment
Dim oSession As MAPI.Session
' CDO objects
Dim oMsg As MAPI.Message
Dim oAttachs As MAPI.Attachments
Dim oAttach As MAPI.Attachment
Dim colFields As MAPI.Fields
Dim oField As MAPI.Field

Dim strEntryID As String

' create new Outlook MailItem
Set objApp = CreateObject("Outlook.Application")
Set l_Msg = objApp.CreateItem(olMailItem)
' add graphic as attachment to Outlook message
' change path to graphic as needed
Set colAttach = l_Msg.Attachments

FName = "c:\" & SendToName
FExt = ".gif"

'loop to add each graphical file
For n = 1 To SendFileCount
Set l_Attach = colAttach.Add(FName & CStr(n) & FExt)
'** how can I add (inline) a few hard returns here? **
Next

l_Msg.Close olSave
strEntryID = l_Msg.EntryID
Set l_Msg = Nothing
' POSITION CRITICAL you must dereference the
' attachment objects before changing their properties
' via CDO
Set colAttach = Nothing
Set l_Attach = Nothing

' initialize CDO session
On Error Resume Next
Set oSession = CreateObject("MAPI.Session")
oSession.Logon "", "", False, False

' get the message created earlier
Set oMsg = oSession.GetMessage(strEntryID)
' set properties of the attached graphic that make
' it embedded and give it an ID for use in an IMG tag
Set oAttachs = oMsg.Attachments

' ** to make all images inline- should I just loop and assume they are all
1 to SendFileCount? **
' ** I don't understand what this block does :-/ **
'e.g.
'For q = 1 to SendFileCount
'Set oAttach = oAttachs.Item(q)
'Set colFields = oAttach.Fields
'Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
'Set oField = colFields.Add(&H3712001E, "myident")
'oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
'next q

'existing code that only changes the first attachment
Set oAttach = oAttachs.Item(1)
Set colFields = oAttach.Fields
Set oField = colFields.Add(CdoPR_ATTACH_MIME_TAG, "image/jpeg")
Set oField = colFields.Add(&H3712001E, "myident")
oMsg.Fields.Add "{0820060000000000C000000000000046}0x8514", 11, True
oMsg.Update

' get the Outlook MailItem again
Set l_Msg = objApp.GetNamespace("MAPI").GetItemFromID(strEntry ID)
' add HTML content -- the IMG tag
l_Msg.HTMLBody = "IMG align=baseline border=0 hspace=0 src=cid:myident"
l_Msg.Close (olSave)
l_Msg.Display

' clean up objects
Set oField = Nothing
Set colFields = Nothing
Set oMsg = Nothing
oSession.Logoff
Set oSession = Nothing
Set objApp = Nothing
Set l_Msg = Nothing
End Function


 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie: How can enable VBA projects i Outlook 2003? Manel Moles Outlook and VBA 1 November 9th 06 06:02 AM
Newbie question: How to copy an email item from inbox to a folder Marceepoo Outlook and VBA 1 November 1st 06 06:54 PM
Newbie: Need to read emails that are stored in a folder w/ VBA lwoods Outlook and VBA 4 August 14th 06 11:26 AM
newbie question Mike Archer Outlook and VBA 1 July 17th 06 09:41 PM
Newbie question to CommandBars Claus Schiroky Outlook and VBA 1 May 10th 06 06:01 AM


All times are GMT +1. The time now is 02:55 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.