Run macro automatically at sending an email

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#1
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:

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#3
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!
 

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#5
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
 

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#6
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.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#7
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:

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#8
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!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#9
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.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
#10
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.
 

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#11
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)
 

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
POP3
#12
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.

-
--

-

-
 
Top