Consulting

Results 1 to 6 of 6

Thread: Macro to replace text in current email subject line...

  1. #1
    VBAX Regular lamensterms's Avatar
    Joined
    Apr 2014
    Location
    Pakenham
    Posts
    16
    Location

    Macro to replace text in current email subject line...

    Hey guys,

    I've got this code below (which I got from Stack Overflow), but I cannot get it to work, just wondering if someone could please help me make some changes to get it to function.

    Sub FindReplaceSubject()
    
     Dim myMessage As Outlook.MailItem
     Set myMessage = Outlook.ActiveInspector.CurrentItem
    
    Dim subject As String
    
    subject = myMessage.subject
    subject = Replace(subject, "xxx", "111")
    
    myMessage.subject = subject
    
    End Sub
    What I would like the code to do: find each occurance of "xxx" in the subject, and replace it with "111".

    What the code does: Deletes everything in the subject.

    I am quite new to VB, and I figure I am overlooking something pretty elementary... just hoping someone can show me where I am going wrong.

    Thanks a lot for any help, I look forward to hearing back.

  2. #2
    did you copy and paste the code into this thread or retype it?

    if pasted, i would expect
    myMessage.subject
    to be
    myMessage.Subject


    the most likely would be some typing error
    i can see nothing wrong with the code posted

  3. #3
    VBAX Regular lamensterms's Avatar
    Joined
    Apr 2014
    Location
    Pakenham
    Posts
    16
    Location
    Hi Westconn1,

    Thanks for the reply.

    I did copy and paste the code into the thread... I suppose that would mean that the code I have is "myMessage.subject". This macro is on my work computer, and I am currently not at work, but I will check it out in the morning. Would you expect the case of 'S' in "myMessage.subject" to make a difference? If I cannot find an error within the code, and cannot correct it... how would you suggest I perform the find/replace task?

    Thanks again for getting back to me.

  4. #4
    Would you expect the case of 'S' in "myMessage.subject" to make a difference?
    no, i would expect the outlook IDE to automate the the S to uppercase, that is has not done so may indicate some problem with the mymessage object

    how would you suggest I perform the find/replace task?
    i would expect the code posted to work correctly, and on testing, changed the subject as indicated

  5. #5
    VBAX Regular lamensterms's Avatar
    Joined
    Apr 2014
    Location
    Pakenham
    Posts
    16
    Location
    Hi again westconn1,

    Just wanted to follow up on this one, the macro is still not working. But I have tried to modify the 'case' of the S in "myMessage.subject", and whenever I try to set the 's' to 'S', it reverts back to 's'.

    Does that provide any clues? Is there a way I can repair the IDE?

    Thanks again for your help.

  6. #6
    i tested your code and it worked fine for me
    i can not see any reason why it should not work fine
    is the posted procedure called from some other code, or how is it run?

Posting Permissions

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