Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Copying Message Text (Outlook 2002 VBA)

    I'm just trying to make a little macro that will take the current message's body text and throw it into a new message with some tweaks to the reply-to, subject, and other fields for internal use. Without the recorder though, I am totally lost. [bonk]

    Any help here?

    Thanks!

    Jeb

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    > Programming is hard.
    Indeed.

    I don't know OL02. Outlook 2000, unlike Word, has no concept of a selection or range or paragraph; the entire message body is a single object. Here's a proof of concept to get you started:

    Sub CloneBody()
    Dim itmOld As MailItem, itmNew As MailItem
    'work with message you have open
    Set itmOld = ActiveInspector.CurrentItem
    'create a new message
    Set itmNew = CreateItem(olMailItem)
    'set new body = old body
    'if this is HTML, use .HTMLbody
    itmNew.Body = itmOld.Body
    itmNew.Display
    End Sub

    If you select the word MailItem and hit F1, you should get entr

  3. #3
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Thanks very much Jefferson. It was that "ActiveInspector" doohickey that was eluding me. Your tip about text selection also helps, as now I'm thinking I need to re-think the whole shebang. <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15>

    I'll post what I put together today. Thanks again!

  4. #4
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Following up... Here's what I have so far:

    Public Sub Testing()
    'This macro sends the current message to a toadie and makes some
    'changes to the Subject, Body, and Reply-To fields so that it gets
    'Sent to QA before going out to the customer.

    Dim Question As MailItem
    Dim SupportMessage As MailItem

    Set Question = ActiveInspector.CurrentItem
    'Question is the incoming message.

    Set SupportMessage = CreateItem(olMailItem)
    'Create the new message.

    SupportMessage.Recipients.Add ("toadie@example.com")
    'Send it to toadie.

    SupportMessage.Subject = "SUPPORT: " & Question.Subject
    'Append a "trigger-word" to the subject so QA knows it's for customers.

    SupportMessage.Body = "From: " & Question.SenderName & Chr(10) & Chr(10) & Question.Body
    'Start the message with the customer's name, throw in
    'some returns and then append the customer's message.

    SupportMessage.ReplyRecipients.Add ("QA@example.com")
    'Put QA in the "Reply-To" field.

    SupportMessage.Display
    'Change to Message.Send to make it live.
    End Sub

    Right now, what's getting me is that I am losing the Sender's ADDRESS. I can grab their name no problem, but I can't tease out MailItem.SenderAddress or any similar property as a text string.

    I also will need to append an if/then to handle HTML messages and at the end I'll throw on a user form that will pop up a list of names for the tech support guy to pick his "toadie" from, but that's not much trouble.

    I really want that SenderAddress--more help please! <img src=/S/help.gif border=0 alt=help width=23 height=15>

  5. #5
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Jeb,

    Nice little routine. Isn't the SenderAddress just the To:
    (recipient) of the orginial message?

    Before you create a new item, grab the recipient with

    Question.To

    If, however, by SenderAddress you mean the address of the
    person sending the message to the To: above, then the
    property you want is:

    Question.SentOnBehalfOfName
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  6. #6
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23> Bwah-bwaaaanh. <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    The SentOnBehalfOfName is the same thing as SenderName if the person sent it themselves. (The SOBON is for lazy bosses that have used Exchange to allow others to send mail with their name on it.)

    The .To property is close--it's actually an email address in a string, but it's the wrong one--I want the one of the person who is sending the msg to us. Here's the situation to clear things up...

    Joe User sends an email to techsupport@example.com. This message goes to one dude in tech support who farms it out to toadies. Toadies answer the question, then send it to QA for verification before they send it back to Joe User. So, unless I preserve that Joe User email address somewhere, I'm going to lose it in the tech support to toadie connection.

    Hopefully someone will find that string I'm after, but until then, I'll be looking into forwarding on the first step and building the macro for toadies....

  7. #7
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Ok. I get it now. Sorry for causing the increased hair loss.

    Now why is that property so elusive? Sender's Email address should not be a mystery. Hope somebody knows. I can't stand the suspense.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  8. #8
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Jeb,

    Don't know if this helps you, but I discovered that

    .ReplyRecipientNames

    will return the email address of the Sender IF the sender's name is not resolvable as an Exchange address.


    Yes?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  9. #9
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    No. Dang. I actually waded through about 4 buzillion pages in the microsoft kb looking for some type of clue. I think I'll try to Redirect the message to toadies and see what happens to these fields then...

    You can try the macro above with a Debug.Print Question.ReplyRecipientsNames entry and you'll see that you usually get nothing. At least I wasn't. (I ran on your post to my Inbox) <img src=/S/grin.gif border=0 alt=grin width=15 height=15>

    <img src=/S/igiveup.gif border=0 alt=igiveup width=31 height=23>

    I'll keep up with this, but who'd'a thought it'd be this hard?

  10. #10
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    This is MS's approach to keeping the email virus hackers at bay. If you can't get at the adress in the mail message, you can't send out the dreaded virus.

    Here's a clue: the MAPI property PR_EMAIL_ADDRESS. My problem at this point is how to access this property.
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  11. #11
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    I think we're done because I think you're right. Remember those carefree days of complete object models?
    <img src=/S/wink.gif border=0 alt=wink width=15 height=15> Ahhh...the good life...

    Man. I'd be set if they would just disable OnOpen type events instead of properties like this--I'm willing to click a button!

    All right. I'll scrap this one and try to get at it from a different route...

    Set VbaProject.OTM to <img src=/S/toilet.gif border=0 alt=toilet width=24 height=26>

  12. #12
    Gold Lounger
    Join Date
    Dec 2000
    Location
    Hollywood (sorta), California, USA
    Posts
    2,759
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    >>days of complete object models?

    Come again... Which days were those?
    Kevin <IMG SRC=http://www.wopr.com/w3tuserpics/Kevin_sig.gif alt="Keep the change, ya filthy animal...">
    <img src=/w3timages/blackline.gif width=33% height=2><img src=/w3timages/redline.gif width=33% height=2><img src=/w3timages/blackline.gif width=33% height=2>

  13. #13
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Here you go - a function you can tweak, and a test procedure for it:

    Sub FromWhenceCameThisOpenMailItem()
    MsgBox RecipAddr(ActiveInspector.CurrentItem)
    End Sub

    Function RecipAddr(myMailItem As MailItem) As String
    Dim myReply As MailItem
    Set myReply = myMailItem.Reply
    With myReply.Recipients(1)
    RecipAddr = .Name & " <" & .Address & ">"
    End With
    myReply.Delete
    Set myReply = Nothing
    End Function

  14. #14
    winter
    Guest

    Re: Copying Message Text (Outlook 2002 VBA)

    A bug to be aware of: In Outlook itself, the message body can be long, but reading it through the VBA .Body property truncates very long messages to a little under 64K

    fw

  15. #15
    Lounger
    Join Date
    Jul 2001
    Location
    Agoura Hills, California, USA
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Copying Message Text (Outlook 2002 VBA)

    Thank you very much.

    <img src=/S/thumbup.gif border=0 alt=thumbup width=15 height=15>

    This is going to be able to pull this off I'm pretty sure. I'll test it out and get back to you!

    Ooh, hey, thanks for the tip about 64kb Winter--good to know.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •