Can I disable or skip "fillin" fields.

M

Mike Kaplan

I have a need to write a VB program, which will use OLE-Automation to
automatically open and print a series of MS Word documents (Word 97 right
now, but soon Word 2003 as well). It seems for some of these documents, the
original authors included fill-in fields, in the document header. Each time
my program opens, and then attempts to print the document, the fill-in prompt
appears.

This program is supposed to require no user-intervention! Right now, I need
to manually click "cancel" twice for these documents. Is there any way to
programatically disable or "skip" these fields?

Thanks
 
J

Jay Freedman

On Thu, 17 Mar 2005 12:17:01 -0800, "Mike Kaplan" <Mike
I have a need to write a VB program, which will use OLE-Automation to
automatically open and print a series of MS Word documents (Word 97 right
now, but soon Word 2003 as well). It seems for some of these documents, the
original authors included fill-in fields, in the document header. Each time
my program opens, and then attempts to print the document, the fill-in prompt
appears.

This program is supposed to require no user-intervention! Right now, I need
to manually click "cancel" twice for these documents. Is there any way to
programatically disable or "skip" these fields?

Thanks

Hi Mike,

Assuming oWord is the Word application object in your VB program, if
you execute the line

oWord.ActiveDocument.Fields.Locked = True

then none of the fields in the document will update until you reset
the value to False.

If you need some fields to update (such as Date and Time fields) but
not others, you can loop through the document's fields and only lock
the ones that are fillins:

Const wdFieldFillIn = 39
Dim oFld As Word.Field
For Each oFld In oWord.ActiveDocument.Fields
If oFld.Type = wdFieldFillIn Then
oFld.Locked = True
End If
Next oFld
 
G

Greg Maxey

Jay,

Thanks. I was this close to posting a solution this afternoon and got
called away to as staff meeting :-(

Sub Test()
Dim oFld As Word.Field
For Each oFld In ActiveDocument.StoryRanges(wdPrimaryHeaderStory)
If oFld.Type = wdFieldFillIn Then
oFld ?
End If
Next oFld
End Sub

I don't know how I missed "locked'
 
J

Jay Freedman

Hi Greg,

I missed the statement in the original post that the field is in the header.
My macro wouldn't have locked any fields there. What's needed is the
combination of our macros:

Const wdFieldFillIn = 39
Dim oFld As Word.Field
For Each oFld In _
oWord.ActiveDocument.StoryRanges(wdPrimaryHeaderStory).Fields
If oFld.Type = wdFieldFillIn Then
oFld.Locked = True
End If
Next oFld
 
J

Jay Freedman

Jay,

What is the significance of:
Const wdFieldFillIn = 39 ?

The OP said he was working in VB. Unless he's doing early binding, VB
doesn't have access to the VBA library that defines the values of
Word's constants, so you have to declare them in the VB code. Since
most non-Word folks don't know how to find the values (in the Object
Browser), I thought it would be helpful to include that one in my
answer.
 
G

Greg Maxey

Jay,

Goes to show how little I know. I didn't know that there was a difference
between VB and VBA. I have a lot to learn.
 
M

Mike Kaplan

Greg and Jay,

Thank you both for your suggestions! I would have got to them sooner, but I
was out sick and had trouble accessing the forum yesterday. I will try these
out ASAP. Hopefully, I have no more questions.

Thanks!
Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top