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:

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Add
Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
  launch the macro here
End Sub
to the ThisOutlookSession module.
 

ofw62

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

Michael Bauer

Senior Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
simply place the name of the macro you wanna call into the shown ItemSend procedure.
 

ofw62

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
Office 365 Exchange
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
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
Office 365 Exchange
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
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
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
Office 365 Exchange
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
Office 365 Exchange
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.
Thread starter Similar threads Forum Replies Date
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
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
O VBA to Run Font Change on Outlook Startup Outlook VBA and Custom Forms 4
D Creating an outlook session from Access vba but run silently. With A specific profile Outlook VBA and Custom Forms 1
Diane Poremsky Run a Script Rule: Send a New Message when a Message Arrives New Slipstick.com Articles 2
Diane Poremsky Using Scanpst in Outlook Click to Run New Slipstick.com Articles 0
oliv- How to Run a Script IN AN ADDIN with Outlook's Rules and Alerts Outlook VBA and Custom Forms 2
L Run a Script Rule doesn't work Using Outlook 5
J Outlook 2010 VBScript editor does not run code at all Outlook VBA and Custom Forms 0
X Outlook script to run excel data Outlook VBA and Custom Forms 1
D How to Run a Report Based on Age of Inbox Items Outlook VBA and Custom Forms 0
D RUN SCRIPT WHEN OUTLOOK IS CLOSE Outlook VBA and Custom Forms 1
L Cannot run script from rule Outlook VBA and Custom Forms 7
M Office 365 Click to run BCM (Business Contact Manager) 0
O modify vba to run it as script rule Outlook VBA and Custom Forms 8
D Must now "View on Facebook" for Mentions/Comments-Outlook 2013 click-to-run Using Outlook 2
P How many subs can run in one outlook VBA script Using Outlook 5
R Outlook won't run except in Safe mode problem Using Outlook 5
K Revert AutoArchive settings via GPO (Run Autoarchive every...) Using Outlook 4
Xueying run a script in rules, first time succeed, failed afterwards Outlook VBA and Custom Forms 3
G Outlook 2003 VBA Won't Run In Outlook 2010 Outlook VBA and Custom Forms 4
J Run Rules Now Using Outlook 1
Similar threads


















































Top