#1
|
|||
|
|||
Auto-update field codes in Outlook Template - AutoOpen Macro not working
Hi All,
A complete VBA newbie here. I’m want to auto update field codes in an Outlook Template. I’ve tried writing a macro with Auto_Open(), AutoOpen(), and Workbook_Open functions, but no luck. I have my settings on outlook to allow any macro. I added a new module that says: Sub Auto_Open() ActiveDocument.Fields.Update End Sub I also tried putting the code in “this outlook session”. The macro runs properly when I click on it, but does not auto run. Thanks! |
#2
|
||||
|
||||
When exactly do you expect to run this macro? What is the nature of the template?
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
#3
|
|||
|
|||
Hey,
I'd like it to run when I open the template (double click on the Outlook Template file on my desktop) Template: I just opened a new message (typed a bunch of stuff) and then went "save as outlook template". The rest of the message is all text, but there's a date field code that should change according to today's date. It's actually 3 field codes because the date has a sub-scripted ordinal in it. Thanks! |
#4
|
|||
|
|||
I'm also not sure the macro is actually attached to the template. When I send the template to others, the macro doesn't seem to be attached.
|
#5
|
|||
|
|||
Perhaps it would be smarter to make a button that runs a macro that opens the template and updates the fields. ... Not totally sure how to do that yet...
|
#6
|
||||
|
||||
What you are trying to achieve is not possible. Outlook templates do not store macros and while the Outlook editor is Word based it is only superficially like Word. If it was for your own use, you could add a macro to Outlook to enter or change the date in the message body, but you couldn't transport it with the template for other users.
If that will suffice then the following macro in your ThisOutlookSession folder will update and fix the date field (if present) when you click 'Send' for all messages. Code:
Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean) Dim olInsp As Inspector Dim wdDoc As Object Dim orng As Object Dim ofld As Object With Item Set olInsp = .GetInspector Set wdDoc = olInsp.WordEditor Set orng = wdDoc.Range For Each ofld In orng.Fields If ofld.Type = 31 Then ofld.Update ofld.Unlink End If Next ofld .Display .Save End With lbl_Exit Exit Sub End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
Tags |
auto update, macro, outlook template |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA script to update field codes? | Calab | Word VBA | 1 | 04-07-2014 09:27 PM |
Auto Update Fields Macro | kveldulv | Outlook | 0 | 06-07-2013 02:30 PM |
Macro to update ole links not working | kisa500 | PowerPoint | 7 | 02-05-2013 03:52 AM |
Auto update Filename field | Oliver Beirne | Word VBA | 4 | 10-19-2012 03:33 AM |
Table of Contents - Direct Field Implementation - Auto-Update Numbering | ztag | Word | 3 | 01-19-2012 03:04 PM |