WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Word

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Word Fields

 Keywords:  Word Word.Application Field Fields Date List Enumerate wdFieldCreateDate wdFieldDate

Question:

When an MSWord document has date fields and you print the document, it updates the field data to the current date. I need to be able to determine if a document contains these date fields. I have done a bit of research online and can't find anything about detecting these fields.

Answer:

See Fields collection and Fields Object ...http://msdn.microsoft.com/en-us/library/bb211922(v=office.12).aspx
; wdFieldCreateDate = 21 ; CreateDate.
; wdFieldDate = 31 ; Date.

strFilename = FileLocate ("Word.Example.docx")

objWord = ObjectCreate ("Word.Application")
objWord.Visible = @TRUE
objDoc = objWord.Documents.Open(:: Filename = strFilename, ReadOnly = @TRUE, Visible = @TRUE)

strMsgTitle = "Fields count = " : objDoc.Fields.Count
ForEach objField In objDoc.Fields
   strMsgText = "Field Index = " : objField.Index
   strMsgText = strMsgText : @LF : "Field Type = " : objField.Type
   strMsgText = strMsgText : @LF : "Field Code = " : objField.Code.Text
   strMsgText = strMsgText : @LF : "Field Text = " : objField.Result.Text
   Pause (strMsgTitle, strMsgText)
Next

:CANCEL
objDoc.Close
objWord.Quit
DropWild ("obj*")
Exit

Article ID:   W18153
Filename:   Word Fields.txt
File Created: 2012:06:27:07:38:48
Last Updated: 2012:06:27:07:38:48