Replace a string in body

Status
Not open for further replies.

Beeto

New Member
Outlook version
Outlook 365 32 bit
Email Account
POP3
Hi all,

I have a problem with this code VBA. Works well when I send a message, replace the year. The problem is when I need to replay or forward a message, don´t replace and give me a Error 91. I would like this code for change the years old of company in my signature.

Thank for your help :).

***************Code**************************
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim dataY As Date, year_X As Double
dataY = Date
year_X = Year(dataY) - 1973
Application.ActiveInspector.CurrentItem.HTMLBody = Replace(Application.ActiveInspector.CurrentItem.HTMLBody, "#year_old#", year_X)
End Sub
**********************************************
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Are you using the reading pane to reply? That doesn't use active inspector, it uses ActiveInlineResponse.

Actually, in looking closer, you're using item send - it doesn't use current item, just item - the message is the item in "item as object"

Try this instead -
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim dataY As Date, year_X As Double
dataY = Date
year_X = Year(dataY) - 1973
item.HTMLBody = Replace(item.HTMLBody, "#year_old#", year_X)
End Sub
 

Beeto

New Member
Outlook version
Outlook 365 32 bit
Email Account
POP3
Are you using the reading pane to reply? That doesn't use active inspector, it uses ActiveInlineResponse.

Actually, in looking closer, you're using item send - it doesn't use current item, just item - the message is the item in "item as object"

Try this instead -
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
Dim dataY As Date, year_X As Double
dataY = Date
year_X = Year(dataY) - 1973
item.HTMLBody = Replace(item.HTMLBody, "#year_old#", year_X)
End Sub
Diane, you are the best :)! You were absolutely right about reading panel to answer or forward. I followed your suggestion and Works 100%. Thank you very much for share your know-how 🥂.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
S HTML Code Embedded in String Within Open Outlook Email Preventing Replace(Application.ActiveInspector.CurrentItem.HTMLBody From Working Outlook VBA and Custom Forms 4
O Replace hard returns with soft returns on selected text and button to QAT Using Outlook 5
O How to find and replace a word in Outlook-Agenda-Subject and Message? Using Outlook 0
M Outlook 2013 Replace Subject with Conversation (a "hidden" value). Outlook VBA and Custom Forms 0
F Copy and replace not update contact in another pst Using Outlook 0
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
C How to replace or delete first instance of sentence in mail body? Outlook VBA and Custom Forms 1
C replace subject line generated by converting a word document to PDF and sending it to an email Using Outlook 8
Diane Poremsky How to perform a global search and replace Using Outlook 0
B Delete/replace old files and save new attachments Using Outlook 1
Diane Poremsky Replace Display Names with Email Addresses Using Outlook 0
mrje1 Is there a Find and Replace feature in Outlook 2016? Using Outlook 4
J Pull an email address from body and replace reply-to address Outlook VBA and Custom Forms 4
divan Outlook 2007 - Replace email body with custom text Using Outlook 9
E VBScript to replace module? Using Outlook 3
A How to replace column title in address book Using Outlook 1
V Replace only part of subject in OUTLOOK 2003 Outlook VBA and Custom Forms 1
A Replace olFolderContacts for Sharepoint lists in Outlook Outlook VBA and Custom Forms 5
P replace default outlook form with custom form Outlook VBA and Custom Forms 1
A How to replace getcontactsfolder (ol2007) in Outlook 2003 Outlook VBA and Custom Forms 2
B Outlook 365 Populate Outlook Task UDFs from a UDF text string Outlook VBA and Custom Forms 2
S vba outlook search string with special characters Outlook VBA and Custom Forms 1
S VBA search string with special characters Outlook VBA and Custom Forms 1
BartH Add a string to the conditions in .Conditions.BodyOrSubject.Text Outlook VBA and Custom Forms 2
M Adding Macro to populate "to" "subject" "body" not deleting email string below. Outlook VBA and Custom Forms 5
R Sending email copy (*.msg file) of sent email if subject line contains specific string. Outlook VBA and Custom Forms 1
skyfox VBA to search email subject field for a certain string Outlook VBA and Custom Forms 3
C Save Subject of Received Email as a String Outlook VBA and Custom Forms 1
P String manipulation in Outlook VBA Outlook VBA and Custom Forms 2
M Find a String in Email Attachment(s) Outlook VBA and Custom Forms 1
S [O2007] -> How to search for a string in the body and get the line number? Outlook VBA and Custom Forms 1
N Separate string in email body Outlook VBA and Custom Forms 3
T Is it possible to INSERT a string into email body via Shortcut. Outlook VBA and Custom Forms 2
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
K Incorporate selection from combobox into body of email Outlook VBA and Custom Forms 0
C Populate form data into message body Outlook VBA and Custom Forms 1
J Outlook 365 Add keywords from Listbox to the message body where cursor is placed Outlook VBA and Custom Forms 0
Witzker Set Cursor & Focus from any field to the body of a user Contact form in OL 2019 Outlook VBA and Custom Forms 1
J Outlook 2019 Regex email addresses from body Outlook VBA and Custom Forms 6
T 1:1 Datatransfer from incoming mail body to customs form body Outlook VBA and Custom Forms 0
D Copy Appointment Body to Task Body Outlook VBA and Custom Forms 0
S New Outlook Appointment - Select All Body Text and Change Font and Size Outlook VBA and Custom Forms 1
Z Copy specific email body text Outlook VBA and Custom Forms 0
J How do you disable address search box when typing @ in body of email? Using Outlook 0
F Forward incoming email with 4 embedded images in the body without original sender Outlook VBA and Custom Forms 22
M Autoforward just attachment OR just body. Outlook VBA and Custom Forms 0
G Place jpg in body of email Outlook VBA and Custom Forms 1
D Create new email from the received Email Body with attachment Outlook VBA and Custom Forms 10

Similar threads

Top