PDA

View Full Version : Macro to replace text in current email subject line...



lamensterms
04-15-2014, 11:16 PM
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.

westconn1
04-16-2014, 03:18 AM
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

lamensterms
04-16-2014, 04:28 AM
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.

westconn1
04-16-2014, 05:11 AM
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

lamensterms
04-21-2014, 04:26 PM
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.

westconn1
05-12-2014, 04:39 AM
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?