Writing text to the "read message"

C

cmonroe21

Hi there. I have a project that I have been unable to get help on, so I went
out and bought MS Outlook 2007 Programming the book, and am still having
problems :(

What I'm doing here is creating an email with a number of fields and controls
for the composer to use. The recipient of this email is going to be a
computer that can extract data from text in the email message box. So, I
need to be able to print the user-selected contents of the controls (via .
Value or .Text ???) in text form onto the "read message" email message. The
forms are created, I just don't know how to access the Read Message box.

Thank you so much! I look forward to hearing from you!
 
K

Ken Slovak - [MVP - Outlook]

If this code is running in the form then use Item.Body for the plain text
contents and Item.HTMLBody for any HTML contents (which must be in correct
HTML syntax).

If the code is running in the Outlook VBA project or elsewhere and the email
where you want to place the text is the ActiveInspector then use
Application.ActiveInspector.CurrentItem.Body or .HTMLBody. With standalone
or COM addin code instantiate an Outlook.Application object (in a COM addin
from the trusted Application object that's passed to you) and use that
instead of Application.

Which book did you buy?
 
C

cmonroe21 via OfficeKB.com

I bought Microsoft Outlook 2007 Programming. It's a good book, but I needed
to be able to create a compose message that was a form with text boxes and
comboboxes, and a read message that was a regular email message with the info
from the controls printed in plain text, and it wasn't easy to find the exact
answers I was looking for. But I found MSDN.microsoft.com and was able to
get tons of info pertinent to my project. I've decided to go with the MS Vba
editor rather than using the Outlook script editor, and I've decided to
(instead of messing with the "compose" message vs. "read" message, and the
Message and P.2 tabs) go with a form that sends a MailItem on a command
button click.

BUT... my NEXT question... (you still think you wanna help?!) I need to get
this new MailItem into a basic font so that I can use tabs and have the data
line up nicely. I tried using & vbTab, but it just adds 5 spaces, so the
data is still not very pretty. I also tried lining them up via spaces (as
you can see below) but again, not pretty. What's important is that the data
starts on the same space in each line (that's how the software I'm sending
the message to will extract it), but I also want it to look pretty. So, I
need to get it into, oh I don't know what you call it... a font where each
character takes up the same amount of space. A monospace font? But I need
to be able to modify the font of the newly created outgoing MailItem. Got
any suggestions?

Here's the code of the command button:

Private Sub cmdSendSub_Click()
'FYI prefix txt denotes a textbox, cmb a combobox
Dim NewEmail As Outlook.MailItem
On Error Resume Next 'do I need this? How does the "Next" work?
Set NewEmail = Application.CreateItem(olMailItem)
NewEmail.To = txtTo.Text
NewEmail.Subject = txtSubject.Text

'Add attachment to email later (NewEmail.Attachments.Add ??)
'...as you can see, my next question will address an attachment :)

'Set font of NewEmail

NewEmail.Body = _
"Date: " & txtDate.Text & vbCrLf & _
"Campus: " & cmbCampus.Text & vbCrLf & _
"Trans Type: " & cmbTransType.Text & vbCrLf & _
"Post Value: " & txtPost.Text & vbCrLf & _
"Adj Value: " & txtAdjustment.Text & vbCrLf & _
"Total: " & txtTotal.Text & vbCrLf
NewEmail.Send
End Sub


Wow. See, even here they do not line up (they were lined up in the Vba
Editor). Hmph.


If this code is running in the form then use Item.Body for the plain text
contents and Item.HTMLBody for any HTML contents (which must be in correct
HTML syntax).

If the code is running in the Outlook VBA project or elsewhere and the email
where you want to place the text is the ActiveInspector then use
Application.ActiveInspector.CurrentItem.Body or .HTMLBody. With standalone
or COM addin code instantiate an Outlook.Application object (in a COM addin
from the trusted Application object that's passed to you) and use that
instead of Application.

Which book did you buy?
Hi there. I have a project that I have been unable to get help on, so I
went
[quoted text clipped - 11 lines]
Thank you so much! I look forward to hearing from you!
 
C

cmonroe21 via OfficeKB.com

I'm going to post this as a new thread, too.
I bought Microsoft Outlook 2007 Programming. It's a good book, but I needed
to be able to create a compose message that was a form with text boxes and
comboboxes, and a read message that was a regular email message with the info
from the controls printed in plain text, and it wasn't easy to find the exact
answers I was looking for. But I found MSDN.microsoft.com and was able to
get tons of info pertinent to my project. I've decided to go with the MS Vba
editor rather than using the Outlook script editor, and I've decided to
(instead of messing with the "compose" message vs. "read" message, and the
Message and P.2 tabs) go with a form that sends a MailItem on a command
button click.

BUT... my NEXT question... (you still think you wanna help?!) I need to get
this new MailItem into a basic font so that I can use tabs and have the data
line up nicely. I tried using & vbTab, but it just adds 5 spaces, so the
data is still not very pretty. I also tried lining them up via spaces (as
you can see below) but again, not pretty. What's important is that the data
starts on the same space in each line (that's how the software I'm sending
the message to will extract it), but I also want it to look pretty. So, I
need to get it into, oh I don't know what you call it... a font where each
character takes up the same amount of space. A monospace font? But I need
to be able to modify the font of the newly created outgoing MailItem. Got
any suggestions?

Here's the code of the command button:

Private Sub cmdSendSub_Click()
'FYI prefix txt denotes a textbox, cmb a combobox
Dim NewEmail As Outlook.MailItem
On Error Resume Next 'do I need this? How does the "Next" work?
Set NewEmail = Application.CreateItem(olMailItem)
NewEmail.To = txtTo.Text
NewEmail.Subject = txtSubject.Text

'Add attachment to email later (NewEmail.Attachments.Add ??)
'...as you can see, my next question will address an attachment :)

'Set font of NewEmail

NewEmail.Body = _
"Date: " & txtDate.Text & vbCrLf & _
"Campus: " & cmbCampus.Text & vbCrLf & _
"Trans Type: " & cmbTransType.Text & vbCrLf & _
"Post Value: " & txtPost.Text & vbCrLf & _
"Adj Value: " & txtAdjustment.Text & vbCrLf & _
"Total: " & txtTotal.Text & vbCrLf
NewEmail.Send
End Sub

Wow. See, even here they do not line up (they were lined up in the Vba
Editor). Hmph.
If this code is running in the form then use Item.Body for the plain text
contents and Item.HTMLBody for any HTML contents (which must be in correct
[quoted text clipped - 14 lines]
 
K

Ken Slovak - [MVP - Outlook]

Plain text is almost impossible to align correctly and unless you're using
WordMail and use the Word object model to format things you can't even
access things like font, etc. in a plain text message. For that you'd use
Inspector.WordEditor which is a Word.Document object.

If it's HTML then you use Inspector.HTMLEditor and that's an IHTMLDocument
object and then you'd use syntactically correct HTML to set things.

For RTF you really need to be deep into knowing RTF codes so that's not a
path I'd take.

That's it for the Outlook object model.

Probably the best way is to format things as a Word table and use WordMail
to get things nicely aligned as you want.
 
C

cmonroe21 via OfficeKB.com

Thanks so much for your help!
Plain text is almost impossible to align correctly and unless you're using
WordMail and use the Word object model to format things you can't even
access things like font, etc. in a plain text message. For that you'd use
Inspector.WordEditor which is a Word.Document object.

If it's HTML then you use Inspector.HTMLEditor and that's an IHTMLDocument
object and then you'd use syntactically correct HTML to set things.

For RTF you really need to be deep into knowing RTF codes so that's not a
path I'd take.

That's it for the Outlook object model.

Probably the best way is to format things as a Word table and use WordMail
to get things nicely aligned as you want.
I bought Microsoft Outlook 2007 Programming. It's a good book, but I
needed
[quoted text clipped - 54 lines]
Wow. See, even here they do not line up (they were lined up in the Vba
Editor). Hmph.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top