Run macro automatically at sending an email

Status
Not open for further replies.

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Found a macro that replaces hard returns with soft returns

2018-08-25_13-38-57.png


As known the use of hard returns causes double line spacing when exchanging mail with gmail.
(I know... there is a AutoHotKey solution. For a while, it worked fine for me. Then it stopped and I couldn't get it going anymore. Couldn't figure out why it stopped, so in the end I gave up on that)

Anyway, the macro works well but requires to be launched manually.

It would be nice if the macro would run at sending a mail.
Is there an easy way to do that?

Thanks!

p.s.: there is one drawback, the macro also removes the graphic email separator (when replying)

SnagIt-25082018 135452.png
 
Last edited:
Thanks a lot!

Sorry to say but I have absolutely no knowledge about these matters. So, before doing anything that is most probably wrong, I would like to provide some additional details.

Screenshot A: shows what the macro does.
Screenshot B: the code and where the module is located

SnagIt-27082018 073938.png


SnagIt-27082018 075006.png



The macro itself

=
Code:
Sub ReplaceHardReturns()
'
'
Dim wdSelection As Word.Selection
Dim wdDoc As Word.Document

    Set wdDoc = Application.ActiveInspector.WordEditor
    Set wdSelection = wdDoc.Windows(1).Selection

    wdSelection.Find.ClearFormatting
    wdSelection.Find.Replacement.ClearFormatting
    With wdSelection.Find
        .Text = "^p"
        .Replacement.Text = "^l"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    wdSelection.Find.Execute Replace:=wdReplaceAll
End Sub

=

Could you please help me out on this?

Many thanks!
 
Bad luck, it doesn't work.
When r-clicking on ThisOutlookSession and insert module, it will insert the module at the very bottom, not below the 'ThisOutlookSession' branch.
When double clicking 'ThisOutlookSession' a window opens where I can put the code in, but I got errors when closing.
When I only put the macro name in it, i.e. just the word: ReplaceHardReturns() it is 'red'
When I put in in Sub ReplaceHardReturns() an error, it requires an end sub
When I punt in the entire code (from sub until end sub) I also get an error (forgot what error)
When the code is at the bottom, it does not work.

I give up...

Sorry, forget it.

Hopefully, one day, in 2025 Microsoft will come up with a solution...

SnagIt-28082018 085849.png


SnagIt-28082018 090445.png
 
I gave a try again and manage to solve it.



=


=

the only relatively small drawback is that the horizontal graphic line, meant as message separator, will be gone, after sending replies back and forth.
probably this can't be solved.

I still went on with this because the autohotkey solution has some effects on other applications.
Like my password manager (popping up each time when I use the enter key in case of e.g. a google search)
or Excel, where the cursor is moving to the left when hitting the enter-key, whereas Excel is configured in a way that should in fact move right.
 
I have a reply macro that also removes it. In that, I was able to add it back because I have the original message body. On this, you wont know where it belongs. One option: add a line after your signature to help highlight the start of the original message.
 
Last edited:
Dear Diane,
Thanks for your comments.
Up front, I confess, it is me alright - so I take the blame ...
I don't mind that though: am used to it, here at home. If anything at all goes wrong, my wife blames me.... :)

But eh, could you explain a little more what you mean, please?
Do you have different (maybe better) macro?
Signature... I don't have a signature.

Thanks again!
 
I have a macro, that when I hit Reply (or Forward), it removes the line - I had to code the macro to add It back. It works on mine, because I know where it belongs. I'm not sure we can identify the position using your macro.
 
This is how the line is coded - it's right before the From line. There isn't a p wrapped around it so i'm kinda surprised it was removed.

HTML:
<div><div style='border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p><b>From:</b> OutlookForums <no.reply@outlookforums.net> <br><b>Sent:</b> Thursday, September 6, 2018 2:16 AM<br><b>To:</b> Diane Poremsky <diane@slipstick.com><br><b>Subject:</b> Run macro automatically at sending an email - New reply to watched thread<o:p></o:p></p></div></div>


One possible solution - remove this line : .Wrap = wdFindContinue
Then put the cursor in the body below the header block and run the macro. On a message where there is a lot of back and forth, the older lines will be removed, but not the one right under the response.

Also, have you seen Messages are Double Spaced for the Recipient ? See if any of those solutions work for you.
 
Hi Diane,
Thanks again.
Well, I'll let it rest now, the double line spacing is solved (without using the .ahk script, so the ahk script won't interfere anymore)
 
As a 'workaround' for the graphic horizontal message separating line, one might consider using a horizontal line as signature.
I admit, it is less sophisticated, it seems to work though.
Start a New Mail, put the cursor in the body of the text, select 'Format Text' tab, then in the drop down list of 'Borders' select 'Horizontal Line'
Clipboard copy the line (optionally one may set thickness and color of the line)
Then File->Options->Mail->Signature create new and paste the Horizontal line.
Signature to be applied on New messages and Replies/forwards.

Below screenshots show how it looks like.

-
--
-

-
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
X Run macro automatically when a mail appears in the sent folder Using Outlook 5
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 0
Dave A Run macro on existing appointment when it changes Outlook VBA and Custom Forms 1
S VBA Macro - Run-time error '424': object required - Help Please Outlook VBA and Custom Forms 3
B Can't run macro from QAT when emailing from Acrobat Outlook VBA and Custom Forms 0
P Vba script including macro appears in rules but wont run Outlook VBA and Custom Forms 6
Hudas Run Macro when an Email is received Using Outlook 4
L Outlook 2007 Macro to Run a Script From a Contact Form Using Outlook 41
Z Trigger macro to run after a new mail is received in Outlook? Using Outlook 3
D Trigger macro to run when selected email is opened Using Outlook 3
D Create a macro in Outlook to run a rule Outlook VBA and Custom Forms 32
J Can't run macro Outlook 2007 that was created in Word 2007 Outlook VBA and Custom Forms 1
M Run external program from Outlook VBA macro Outlook VBA and Custom Forms 5
J Macro to run on Open Outlook VBA and Custom Forms 2
B Run a macro Outlook VBA and Custom Forms 1
K Macro to Run Rules Outlook VBA and Custom Forms 5
J Outlook, Word, Access crash unless run in Admin mode - time dependent it seems Using Outlook 10
V Outlook macros no longer run until VB editor is opened Outlook VBA and Custom Forms 0
J Want to create a button on the nav bar (module add-in) to run code Outlook VBA and Custom Forms 2
J Outlook Rules VBA Run a Script - Multiple Rules Outlook VBA and Custom Forms 0
N Outlook 2021 'Run Script" Rules? Outlook VBA and Custom Forms 4
T Outlook 2010 Errore run-time -2147417851 (80010105) Metodo delete ContactItem non riuscito Outlook VBA and Custom Forms 0
K Run a script rule to auto 'send again' on undeliverable emails? Outlook VBA and Custom Forms 1
G Save attachment run a script rule Outlook VBA and Custom Forms 0
U Outlook 2019 VBA run-time error 424 Outlook VBA and Custom Forms 2
D Outlook 2013 Macros only run in VB editor, not in drop down or button Outlook VBA and Custom Forms 14
D We're sorry but outlook has run into an error Using Outlook 6
M White square in body of Outlook Messages (O2016 Version 2012 32bit Click To Run) Using Outlook 4
E Having some trouble with a run-a-script rule (moving mail based on file type) Outlook VBA and Custom Forms 5
C Auto Run VBA Code on new email Outlook VBA and Custom Forms 1
Aussie Rules Run a Script on an Incoming Email OK and then the Email reverts Outlook VBA and Custom Forms 0
A Apply Selected Emails to outlook rules and Run Rules Using Outlook 5
B VBScript doesn't run on Recipient Email Outlook VBA and Custom Forms 2
A Run-time error '430' on certain emails when trying to set "Outlook.mailitem" as "ActiveExplorer.Selection.Item" Outlook VBA and Custom Forms 2
S Outlook Custom Form Scripting only working when clicking on "Run this form" Outlook VBA and Custom Forms 2
Y Outlook 2013 Run A Script Outlook VBA and Custom Forms 4
O Outlook 2016 This rule will only run when you check your email in Outlook.... Using Outlook 4
B run scripts Using Outlook 1
A Run time error 424. object required in outlook 2013 Outlook VBA and Custom Forms 10
P errors appear every time I run SCANPST Using Outlook 3
B Outlook rule run a Script doesn't work Outlook VBA and Custom Forms 1
B Wanting to run a script that will filter any body that has a russian link in it. Outlook VBA and Custom Forms 5
P Run Time Error 91 when linking contact to task in VBA Outlook VBA and Custom Forms 1
O Having rules run on old mails noved to inbox Outlook VBA and Custom Forms 8
Bri the Tech Guy Registry Tweak to make "Run a Script" Action Available Outlook VBA and Custom Forms 2
Bri the Tech Guy Run Script rule not running for newly arriving messages Outlook VBA and Custom Forms 25
J Custom form code doesn't run Outlook VBA and Custom Forms 2
J VBA Run When Reply Outlook VBA and Custom Forms 4
Vijay Error in rule- Run a script Using Outlook 1
Vijay Run script doesn't work in outlook Using Outlook 1

Similar threads

Back
Top