Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Recurring e-mail message (Outlook 2002 )

    I am using the following code from MS's website. How to Create a Recurring E-mail Message. Where I type the text for "NewItem.Body" I want to be able to type more than one paragraph, so I need to know how to indicate a hard return, if possible. Also, I want the recurring e-mail to have the signature that automatically inserted on new messages. Is there a way to do those two additional things? TIA.

    Sub Item_PropertyChange (ByVal Name)
    Select Case Name
    Case "Status"
    if Item.Status = 2 then '2 = Completed
    Set NewItem = Application.CreateItem(O)
    NewItem.To = "myemailaddress@myisp.com"
    NewItem.Bcc = "bccemailaddress@theirisp.com"
    NewItem.Recipients.ResolveAll
    NewItem.Subject = "This is the message subject text."
    NewItem.Body = "This is text that will appear in the body of the message."
    NewItem.Display
    End IF
    End Select
    End Sub
    egghead

  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: Recurring e-mail message (Outlook 2002 )

    The vb constant for a paragraph break is vbCrLf, and you can & that in to your strings without " marks.

    Unfortunately, when you assign a string to the .Body, it completely replaces what was there before. Thus, I think you have to add the signature into your string assignment. I haven't looked at the Outlook object model to see how you would access a saved signature, but if it's just as easy to add the signature text into your code, that probably would be just as fast.

  3. #3
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    Can you give me an example of how I would use vbCrLf and the &'s? I'm extremely new, but wanting to learn!

    Thanks!
    egghead

  4. #4
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    <pre>Sub Item_PropertyChange (ByVal Name)
    dim strMsg as String

    strMsg = "Here is the first paragraph of my message"
    strMsg = strMsg & vbCrLf & "Here is the next paragraph"
    strMsg = strMsg & vbCrLf & vbCrLf & "And here is the signature"

    Select Case Name
    Case "Status"
    if Item.Status = 2 then '2 = Completed
    Set NewItem = Application.CreateItem(O)
    NewItem.To = "myemailaddress@myisp.com"
    NewItem.Bcc = "bccemailaddress@theirisp.com"
    NewItem.Recipients.ResolveAll
    NewItem.Subject = "This is the message subject text."
    NewItem.Body = strMsg
    NewItem.Display
    End If
    End Select
    End Sub
    </pre>


  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    I've seen this method of building up in strings in VB howto guides - wonder if it dates to versions prior to the introduction of the line continuation character. Doing it like this:

    <pre>Dim strMsg As String
    strMsg = "Here is the first paragraph of my messages" _
    & vbCrLf & "Here is the next paragraph" _
    & vbCrLf & vbCrLf & "And here is the signature"
    </pre>

    seems to me to have two advantages:
    1) it's a bit quicker to type since you don't have to repeat "strMsg" each time
    2) the code is more efficient/requires less overhead since you're only assigning a value to strMsg once.

    Gary

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    Hi Gary,
    For shorter strings, the line continuation character is my preference but there is a limit as to how many of those you can use. If I'm building complex SQL statements in code, I tend to use Stuart's method of strSQL = strSQL & "..."
    FWIW.
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    <img src=/S/hello.gif border=0 alt=hello width=25 height=29> Gary,

    You missed
    3) The code is much easier to read.

    I used this format when I was adding real paragraphs to a letter, I tend to use continuation lines within each paragraph and add paragraphs together with the syntax I showed.

    StuartR

  8. #8
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Recurring e-mail message (Outlook 2002 )

    I use it whenever possible, but I believe it is actually less efficient than the individual string assignments, although I can't remember where I read and explanation that supported that claim. Seems like it was something about each line continuation forcing the entire previous string to be reevaluated or rereferenced or something ...
    Charlotte

  9. #9
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    Thank you!

    If I wanted a blank line would I use this?

    strMsg = strMsg & vbCrLf & " "

    Or is there a better way?
    egghead

  10. #10
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    The constant vbCrLf gets its name from the old typewriter action of "Carriage Return" followed by a "Line Feed"

    Insert one vbCrLf to get a newline
    Insert two in a row to get a blank line

    <pre>strMsg = strMsg & vbCrLf & vbCrLf
    </pre>


    StuartR

  11. #11
    4 Star Lounger
    Join Date
    Mar 2001
    Location
    Bismarck, ND, USA
    Posts
    451
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    Thanks for the help. I tried typing the code and am getting a script error. It reads
    <hr>Expected end of statement Line No: 2<hr>

    I tried copying and pasting in the code and am getting the same message. Any suggestions?

    Sub Item_PropertyChange (ByVal Name)
    dim strMsg as String

    strMsg = "Here is the first paragraph of my message"
    strMsg = strMsg & vbCrLf & "Here is the next paragraph"
    strMsg = strMsg & vbCrLf & vbCrLf & "And here is the signature"

    Select Case Name
    Case "Status"
    if Item.Status = 2 then '2 = Completed
    Set NewItem = Application.CreateItem(O)
    NewItem.To = "solberg@firesideop.com"
    NewItem.Bcc = "dacksolberg@firesideop.com"
    NewItem.Recipients.ResolveAll
    NewItem.Subject = "This is the message subject text."
    NewItem.Body = strMsg
    NewItem.Display
    End If
    End Select
    End Sub
    egghead

  12. #12
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    I'd never looked at the VB Script for these forms before, it seems to be a strange sub set of Visual Basic.

    Just replace
    <pre>Dim strMsg as String
    </pre>

    with
    <pre>Dim strMsg
    </pre>

    and it will work as advertised

    StuartR

  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: Recurring e-mail message (Outlook 2002 )

    That's right, in VBScript, all variables (even objects) are variants and cannot be dimensioned as a particular type. Hard to undo the habit when posting sample code here!

  14. #14
    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: Recurring e-mail message (Outlook 2002 )

    The article Efficiently Reading Large Text Files on the 4GuysFromRolla ASP site reported some results of different ways of making strings using the FileSystemObject. They found that concatenation was quite slow compared with other methods tested, perhaps because Windows allocates new memory and copies the earlier string each time? Assuming that the same thing would happen here, then the line continuation method should be faster, although with 5 lines, I assume it's an unmeasurable advantage.

    If anyone needs to quickly scan text files in excess of 100Kb using VBA or VBScript, I recommend the above article. Is Chris Greaves listening?

  15. #15
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 29 Times in 27 Posts

    Re: Recurring e-mail message (Outlook 2002 )

    My recollected reading (can't remember specifically where I read it either) was that VB is inefficient with the repeated assignments of a value to "strMsg" - something about a new memory address being allocated for each assignment. What you're recollecting also sounds likely (that internally the line continuation character is forcing some kind of reevaluation or reassignment). May be six of one half dozen of the other....

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
  •