0

Sometimes when sending a new event invitation for a certain meeting in Outlook I need to mention all the required people for the meeting in the invitation body, due to company conventions. Many times, the names I already sent the invitation to are the very same people I need to write all over again. I found that if I copy those names from the "To..." field, they are pasted in the format of name <mail>; name <mail>; name <mail>, so I wrote this Python function to turn it into a plain list of names separated by a new line with the mail addresses removed:

def format_invitees(string):
    import re; return ''.join(x.strip(' \n')+'\n' for x in re.sub("[<].*?[>]", "", string).replace(' ; ', ';').split(';')).strip('\n')

Now, is there any good way to implement this function into an Outlook Macro, with whether to assign it to a hotkey or add it to the menu on right click? To mention that Python is the only language I know, and I am not allowed to install any external software due to organization orders. Best regards!

Iftach
  • 95
  • 2
  • 13
  • This sounds like a problem that is more directly approached/solved in VBA as a standalone script, rather than 'subcontracting' out to Python (don't get me wrong; Python's a great tool too!) -- does https://stackoverflow.com/questions/22542834/how-to-use-regular-expressions-regex-in-microsoft-excel-both-in-cell-and-loops give you a push in the right direction? – Joshua Voskamp Oct 21 '21 at 13:28
  • You can use VBA in Outlook by pressing Alt+F11 without installing any other software. See also this SO answer: https://stackoverflow.com/questions/34070693/regex-in-outlook-vba-to-get-text-from-email-body – Joshua Voskamp Oct 21 '21 at 13:29

1 Answers1

0

I think import re; return re.sub(r" ?<.*?>;? ?","\n",string) is a shorter way of defining the Python function.

But more to your point, follow the instructions at this SO question to enable VBA regex module (given for Word, but applicable in Outlook): How to Use/Enable (RegExp object) Regular Expression using VBA (MACRO) in word

I think the outlook.Recipients property may be useful for getting the names of the people you're needing to list: https://learn.microsoft.com/en-us/office/vba/api/outlook.recipients

Joshua Voskamp
  • 1,855
  • 1
  • 10
  • 13