+ Reply to Thread
Results 1 to 10 of 10

Trying to add a disclaimer to an open email without removing the current body text

  1. #1
    Registered User
    Join Date
    10-25-2022
    Location
    Altus, OK
    MS-Off Ver
    2016
    Posts
    5

    Post Trying to add a disclaimer to an open email without removing the current body text

    So, here's my situation, I'm programming a new button into my active email ribbon to add a "CUI" disclaimer to the subject and the body of the email.
    I'd like to open up a new email, type a message, click the button, and it add the disclaimer before the text in the subject and before the text in the body.
    Right now, every time I try, it deletes and replaces everything in the email like a template when I click the button.

    Here's the code:

    Sub AddCUI()
    Set myFolder = Application.ActiveWindow.CurrentItem
    Set myItem = Application.ActiveWindow.CurrentItem
    myItem.Display
    With myItem
    .Subject = "CUI"
    .HTMLBody = "body of text here"
    .Display
    End With
    End Sub

    I'm not much of a coder, but I'm trying to help out a larger group of people with this.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,373

    Re: Trying to add a disclaimer to an open email without removing the current body text

    Ok, I will start by saying that I have never programmed for Outlook, so this is a guess.

    Assuming that .CurrentItem does what it says on the tin, then I would suggest that you try changing:
    Please Login or Register  to view this content.
    To:
    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    10-25-2022
    Location
    Altus, OK
    MS-Off Ver
    2016
    Posts
    5

    Re: Trying to add a disclaimer to an open email without removing the current body text

    AHHHHH THAT WAS SO SIMPLE!!! Thank you! That worked!

  4. #4
    Registered User
    Join Date
    10-25-2022
    Location
    Altus, OK
    MS-Off Ver
    2016
    Posts
    5

    Re: Trying to add a disclaimer to an open email without removing the current body text

    A second question... So now that I have that working!
    I want to be able to click the button again so that it'll remove what it added without affecting the body of the text or the subject line. How would I go about that?

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,373

    Re: Trying to add a disclaimer to an open email without removing the current body text

    Simplest way, I think, would be to store the Subject and Body in temporary variables BEFORE you overwrite them. Then you can restore them afterwards. For example

    Before:
    Please Login or Register  to view this content.
    After:
    Please Login or Register  to view this content.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,373

    Re: Trying to add a disclaimer to an open email without removing the current body text

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  7. #7
    Registered User
    Join Date
    10-25-2022
    Location
    Altus, OK
    MS-Off Ver
    2016
    Posts
    5

    Re: Trying to add a disclaimer to an open email without removing the current body text

    So where would I add this in my code? Very sorry, I’m not a coder so I’m just trying to learn and figure this out!

    Sub AddCUI()
    Set myFolder = Application.ActiveWindow.CurrentItem
    Set myItem = Application.ActiveWindow.CurrentItem
    myItem.Display
    With myItem
    .Subject = "CUI\" & .Subject
    .HTMLBody = "text here" & .HTMLBody
    .Display
    End With
    End Sub

    I just want to be able to run the macro a second time to remove the disclaimer from the email without removing any other text. If that makes sense?
    Last edited by stembrick; 10-25-2022 at 12:15 PM.

  8. #8
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,373

    Re: Trying to add a disclaimer to an open email without removing the current body text

    Maybe this

    Please Login or Register  to view this content.

  9. #9
    Registered User
    Join Date
    10-25-2022
    Location
    Altus, OK
    MS-Off Ver
    2016
    Posts
    5

    Re: Trying to add a disclaimer to an open email without removing the current body text

    That almost worked... when I click it, it adds and removes it in one click. What would you suggest?

    I have one final ask. So often when my enterprise sends these emails with the CUI message, the subject will already have "CUI//". Is there a command that I can enter to basically tell the code "if it already has CUI in the subject, don't add it again"?

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,373

    Re: Trying to add a disclaimer to an open email without removing the current body text

    The code as shown first displays the current item, saves the subject and body, changes the subject and body, displays (could be changed to send) the amended current item, and finally restores the subject and body. There is not, IMO, a need for a two stage process.

    Is there a command that I can enter to basically tell the code "if it already has CUI in the subject, don't add it again"?
    Well, yes. You know what the subject contains, so test for Left(.Subject, 3) = "CUI".

    As I said, I don't program Outlook so I can't offer definitive advice. That said, you should have the building blocks to do what you have described. I just don't know why you want to.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Text Mail Body and HTML Body in same email
    By dflak in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-27-2022, 04:11 PM
  2. [SOLVED] Generating Outlook Email and inseting chart into email with Text body.
    By Hyperion1571 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-17-2019, 12:41 PM
  3. [SOLVED] VBA to send email using data from the EXCEL including email address, subject and body text
    By ec4excel in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-18-2016, 11:07 AM
  4. look for text in email body and move email to a folder
    By Megatronixs in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-10-2015, 05:23 AM
  5. [SOLVED] Insert Current month into body of email
    By cheeze83 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-13-2013, 08:18 AM
  6. [SOLVED] Adding a disclaimer changes image in email body
    By johncassell in forum Outlook Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2012, 08:42 AM
  7. Replies: 4
    Last Post: 02-27-2012, 03:13 AM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1