Solved

How update specific fields in Word when opening the file?

Posted on 2011-03-04
5
326 Views
Last Modified: 2012-05-11
Hello,

we use Word as default Outlook editor and we made some specific signatures for the people in htm format. My question is, how can I update some specific fields each time I click on new message in Outlook?

I've already a macro that gets info from a LDAP server and I just want that variables to be inserted/updated on a specific field in that signature file.

The final idea is to deploy that file to all my users and I don't have to modify the name, email address, title, etc as all the info is get from the AD.

Kindly Regards,
David
0
Comment
Question by:David_Pazos
  • 4
5 Comments
 

Author Comment

by:David_Pazos
ID: 35037800
Hi,

this is a sample of what I did. The signature file is in htm format, I've added inside 3 form fields named strName, strTitle and strEmail and I populate them when this macro is runned. The thing is, I can't run it automatically when I click new message in Outlook... any suggestions? :/

David
Sub AutoOpen()
'
    Dim objFSO

    Set objFSO = CreateObject("scripting.filesystemobject")

    Set objSysInfo = CreateObject("ADSystemInfo")
    strUser = objSysInfo.UserName
    Set objUser = GetObject("LDAP://" & strUser)

    strName = objUser.cn
    strTitle = objUser.Title
    strCompany = objUser.company
    strPhone = objUser.telephoneNumber
    strEmail = objUser.EmailAddress


   Dim FieldObj As Object

   Set FieldObj = ActiveDocument.FormFields("strName")
   FieldObj.Result = CStr(strName)
   Set FieldObj = ActiveDocument.FormFields("strTitle")
   FieldObj.Result = CStr(strTitle)
   Set FieldObj = ActiveDocument.FormFields("strEmail")
   FieldObj.Result = CStr(strEmail)
End Sub

Open in new window

0
 
LVL 15

Accepted Solution

by:
cquinn earned 500 total points
ID: 35041927
I suspect you may need to call your routine from the ThisOutlookSession Application_NewMail() event, rather than from the Word event
0
 

Author Comment

by:David_Pazos
ID: 35055078
Hi cquinn,

you're fantastic, you definitelly solved my problem )) I added the macro in the "ThisOutlookSession* calling the macro as you mentioned Application_NewMail() and it works!

Many many thanks!!! I've been stuck so long on this.
Have a great day
Kind Regards,
David
0
 

Author Comment

by:David_Pazos
ID: 35055098
oops.. finally, doesn't work totally as expected as it lunchs the macro as well if I get a new email and reports an error... :((( any ideas on how to fix this?
David
0
 

Author Comment

by:David_Pazos
ID: 35056709
ok just added that and that solved my problem ))
On Error GoTo 0
    Exit Sub

Open in new window

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Outlook 2013 Indexing problems 8 20
VBA code to open new email message (Contact Us) 3 32
Assigning VBA code to a specific worksheet 3 24
outlook calendar 2 18
Large Outlook files lead to various unwanted errors and corruption issues. Furthermore, large outlook files can also make Outlook take longer to start-up, search, navigate, and shut-down. So, In this article, i will discuss a method to make your Out…
Read this checklist to learn more about the 15 things you should never include in an email signature.
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question