Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 12-21-2015, 04:35 AM
victoriasun victoriasun is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 7 64bit Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2007
Novice
Auto-update field codes in Outlook Template - AutoOpen Macro not working
 
Join Date: Dec 2015
Posts: 4
victoriasun is on a distinguished road
Default 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!
Reply With Quote
  #2  
Old 12-21-2015, 07:43 AM
gmayor's Avatar
gmayor gmayor is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 10 Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
  #3  
Old 12-21-2015, 08:52 AM
victoriasun victoriasun is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 7 64bit Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2007
Novice
Auto-update field codes in Outlook Template - AutoOpen Macro not working
 
Join Date: Dec 2015
Posts: 4
victoriasun is on a distinguished road
Default

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!
Reply With Quote
  #4  
Old 12-22-2015, 12:32 AM
victoriasun victoriasun is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 7 64bit Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2007
Novice
Auto-update field codes in Outlook Template - AutoOpen Macro not working
 
Join Date: Dec 2015
Posts: 4
victoriasun is on a distinguished road
Default

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.
Reply With Quote
  #5  
Old 12-22-2015, 12:44 AM
victoriasun victoriasun is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 7 64bit Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2007
Novice
Auto-update field codes in Outlook Template - AutoOpen Macro not working
 
Join Date: Dec 2015
Posts: 4
victoriasun is on a distinguished road
Default

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...
Reply With Quote
  #6  
Old 12-22-2015, 01:54 AM
gmayor's Avatar
gmayor gmayor is offline Auto-update field codes in Outlook Template - AutoOpen Macro not working Windows 10 Auto-update field codes in Outlook Template - AutoOpen Macro not working Office 2016
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

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
Reply With Quote
Reply

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
Auto-update field codes in Outlook Template - AutoOpen Macro not working Macro to update ole links not working kisa500 PowerPoint 7 02-05-2013 03:52 AM
Auto-update field codes in Outlook Template - AutoOpen Macro not working 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

Other Forums: Access Forums

All times are GMT -7. The time now is 05:05 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft