How to automatically update all fields in an Outlook message template (OFT)?

Status
Not open for further replies.

ngkatsaras

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
I created an Outlook message template file (OFT), there is a pre-formatted message where the message body contains a couple of field codes as follows:

Dear {FILLIN "Recipient's name"}:

blah blah blah

Kind regards,

{FILLIN "Sender's name"}

This works fine except that whenever I open the template, the fields do not automatically prompt me to update. For now I have instructed the users to do CTRL+A then F9 which will then prompt the user to input the data to be merged into the fields. But that is not as elegant as I would like.

I found out that in a Word template file you could do a macro as follows that will automatically prompt the user for input to define the field codes:

Sub AutoNew()
ActiveDocument.Fields.Update

End Sub

However, I don't seem to be able to get that to work with the OFT file.

I also tried naming the Sub AutoOpen() but that didn't work either.

Your assistance is greatly appreciated in advance.

Kind regards,

Nick K.
 

ngkatsaras

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Re: How to automatically update all fields in an Outlook message template (OFT

Yes, Tools > References > checked Word 14.0 Office Library

So to clarify, what I'm trying to do is have this macro/VBA fire after the OFT creates the new message. I want it to pop up and prompt the user to input and update these field codes within the message body.

CTRL-A and then F9 does what I need, but I want that to happen automatically.

I found some other code that also seems to work in Word, but not in this OFT file:

Sub AutoNew()
Selection.WholeStory
Selection.Fields.Update

End Sub

I think the problem is that the macro needs to act upon the message body (object) portion and I don't know how to make that happen.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: How to automatically update all fields in an Outlook message template (OFT

I assume you have all of the following references set - (all but word should be set by default)

  • Visual Basic For Applications
  • Microsoft Outlook 14.0 Object Library
  • OLE Automation
  • Microsoft Office 14.0 Object Library
  • Microsoft Word 14.0 Object Library
It looks like you will need to get the Word.Document object from Outlook's Inspector.WordEditor object.

Sub AutoNew()

Dim objDoc As Word.Document

Dim objWord As Word.Application

Set objDoc = ActiveInspector.WordEditor

Set objWord = objDoc.Application

objWord.Selection.WholeStory

objWord.Selection.Fields.Update

End Sub

That works when i run it from the VBE.

Are you putting your macro in the template or in the VBE?
 

ngkatsaras

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Re: How to automatically update all fields in an Outlook message template (OFT

Wow, thank you so much! The macro is now working in the Outlook message that is created by running the OFT file. The problem is that it doesn't run automatically. Is that possible?

What I want to do is distribute this OFT file to a bunch of users so they can just use it whenever they need it and I would like for it to automatically prompt to update the fields, if possible.

At this point at least, I can have them run the macro manually, but that's really not much easier than doing CTRL+A then F9. Maybe if there's some way I can include a button in the OFT that will run the macro, is that possible?

Thanks again!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Re: How to automatically update all fields in an Outlook message template (OFT

The users could put it on the ribbon, so its one click or keystroke, but auto-run would be better.

Is the macro in the oft or in Outlook's VB editor? It can be kicked off from the VB Editor with inspectors but i didn't have the code handy and needed to get an article written today. As soon as i get the article finished (whenever possible, I put it off all day long :)), i'll work on it.
 

ngkatsaras

Member
Outlook version
Outlook 2010 64 bit
Email Account
Exchange Server
Re: How to automatically update all fields in an Outlook message template (OFT

>Is the macro in the oft or in Outlook's VB editor?

The macro doesn't seem to be getting saved in the OFT. I have been running it from the VB editor.

I just opened the OFT on another computer and there was no sign of the macro.

Is there a way to include the macro in the OFT?

Thanks again for your help!

Nick
 

jrmehl

Member
Outlook version
Outlook 2010 32 bit
Email Account
Exchange Server
Re: How to automatically update all fields in an Outlook message template (OFT

Hello,

I am trying to do the very same thing, but I'm not completely following what you had to do to make it work. Can you share what you have in your macro please?

Thanks,

Jason
 

Mimi

New Member
Outlook version
Outlook 2007
Email Account
Exchange Server
Hi, has anyone gotten an answer for this? I'm having the same issue. The macro doesn't seem to be attached to the outlook template.
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
Outlook doesn't run autonew macros. You can use a macro to open the template then run the macro.

How to Open Outlook Templates and Files using Toolbar Buttons

This is the first macro on that page merged with the code above:
Code:
Sub MakeItem()
Set newItem = Application.CreateItemFromTemplate("C:\Users\drcp\AppData\Roaming\Microsoft\Templates\test.oft")
newItem.Display


Dim objDoc As Word.Document
Dim objWord As Word.Application
Set objDoc = ActiveInspector.WordEditor

Set objWord = objDoc.Application

objWord.Selection.WholeStory
objWord.Selection.Fields.Update


Set newItem = Nothing

End Sub
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
Cameron Piper Automatically update custom forms across multiple computers Outlook VBA and Custom Forms 1
Alex Hall When updating shared calendar, it does not automatically update personal calendar Using Outlook 3
S New Quick Step based on Team email QS - automatically update too Using Outlook 1
J update a meeting automatically? Using Outlook 1
A Why doesn't distribution lists update automatically Using Outlook 3
Q Sorting tasks by calculated field - automatically update task-fiel Outlook VBA and Custom Forms 9
diver864 vba for a rule to automatically accept meeting requests with 'vacation' in subject, change to all-day event, change to free, don't send reply Outlook VBA and Custom Forms 1
D Custom Search Folders not refreshing/updating automatically Using Outlook 0
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
C Add Form to Appointments Received, Automatically Outlook VBA and Custom Forms 6
J Automatically forward email and apply template Outlook VBA and Custom Forms 0
Y Outlook 2013 Stop Outlook from automatically assigning categories to Tasks Using Outlook 0
O Forward a email with modified body Automatically. Outlook VBA and Custom Forms 0
A How to open a specific link automatically with outlook 2016 Outlook VBA and Custom Forms 6
P Automatically Categorize Meetings once they are accepted Outlook VBA and Custom Forms 5
W Automatically open attachments without automatically printing them Using Outlook 0
N How to set automatically the default or user defined Quickstyle Templates by Answer in Outlook Using Outlook 1
O Run macro automatically at sending an email Using Outlook 11
D Outlook 2016 automatically increment anniversaries Using Outlook 1
T Office 2013 no longer updating automatically Using Outlook 2
B Automatically Forward Emails and Remove/Replace All or Part of Body Outlook VBA and Custom Forms 8
D Print attachments automatically and moves the mail to a new folder Outlook VBA and Custom Forms 9
A How to open a specific link automatically with outlook Outlook VBA and Custom Forms 13
L Automatically Insert Recipient Name from To Field Outlook VBA and Custom Forms 33
N how to sync automatically when outlook opens Using Outlook 10
A Sort emails into subfolders based on sender and deleting emails automatically Outlook VBA and Custom Forms 3
undercover_smother Automatically Forward All Sent Mail and Delete After Send Outlook VBA and Custom Forms 10
C Need VBA code to automatically save message outside outlook and add date Outlook VBA and Custom Forms 1
stephen li VBA Outlook send mail automatically by specified outlook mail box Outlook VBA and Custom Forms 1
R Make Enter Network Password Prompt Go Away Automatically Using Outlook 0
I Print Automatically Attachments Outlook VBA and Custom Forms 3
S Automatically selecting folders and deleting messages in Outlook VBA Outlook VBA and Custom Forms 7
M Outlook 2016 Rules Not Working Automatically Using Outlook 5
Diane Poremsky Automatically create a task when sending a message New Slipstick.com Articles 0
D Is it possible to automatically send an email when it is moved to a folder? Exchange Server Administration 1
A Automatically send email based on drop-down field? Outlook VBA and Custom Forms 2
M Automatically create event in calendar when task is created Outlook VBA and Custom Forms 1
Diane Poremsky Create Appointment From Email Automatically New Slipstick.com Articles 0
T Automatically open link in email received Outlook VBA and Custom Forms 33
N Automatically file email messages Using Outlook 2
J Automatically Move Old Items from a Shared Mailbox to a .PST on a Network Drive Outlook VBA and Custom Forms 1
M Change default "automatically test account settings when Next is clicked" Using Outlook 1
D Automatically file message and reply to folder. Using Outlook 1
A Code to automatically delete message after sending Outlook VBA and Custom Forms 6
Diane Poremsky Automatically Create Contacts From Messages New Slipstick.com Articles 1
T Outlook 2010 emails do not refresh automatically Exchange Server Administration 1
L Save Mail Message to new folder created automatically Outlook VBA and Custom Forms 1
G Hae Rules NOT perform automatically? Using Outlook 1
F Automatically close email after selecting mark unread Using Outlook 1
nathandavies How to save emails to a specific folder on a network automatically using a macro Outlook VBA and Custom Forms 14

Similar threads

Top