Automate filling in protected forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

On a daily basis I have to fill in a form the same way based on a table in
another Word document.
Is there a way I can automate this process? I'm frustrated to find that I
can't run a macro on a protected form. I can easily unprotect the form, but
this makes the process of recording the macro much more difficult (more
fields to navigate etc.)
Any suggestions?
 
There are a number of ways to run a macro on a protected form:

1. On Entry or Exit from a formfield
2. By assigning the macro to the keyboard
3. By assigning the macro to a button on the toolbar.

However, you are probably not going to be able to record a macro for what
you want to do.

You will need to do something like

Dim target as Document, source as Document, datatable as Table, data as
Range
Set target = ActiveDocument 'the protected form document
Set source = Documents.Open("drive\path\filename") 'the document containing
the table
Set datatable = source.Tables(1) 'assumes that the data is in the first
table in the document
Set data=datatable.cells(r#, c#).Range
data.end=data.end - 1
target.formfields("name").Result = data

The last several lines of this code will have to be tailored to your actual
requirements.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
This is extraordinarily helpful. I have one additional question, though.
In trying to implement this, I'm having trouble specifying the range of
cells I would like to use as my range.
The cells are all in row 1, columns 1-27 of the first table in my source
document. Perhaps I'm using incorrect syntax to specify them, but the VB
Debugger keeps saying the method or data member is not found. Here's what I
have:

Dim target As Document, source As Document, datatable As Table, data As Range
Set target = ActiveDocument 'the protected form document
Set source = Documents.Open("c:\documents and
settings\xxxxxx\desktop\foo.doc") 'the document containing the Table
Set datatable = source.Tables(1) 'assumes that the data is in the first
table in the document
Set data = datatable.Cells(R1, C1 - 27).Range
data.End = data.End - 1
target.FormFields(1 - 27).Result = data

Thanks for your help!
 
Dim target As Document, source As Document, datatable As Table, data As
Range, i as Long, ff as string
Set target = ActiveDocument 'the protected form document
Set source = Documents.Open("c:\documents and
settings\xxxxxx\desktop\foo.doc") 'the document containing the Table
Set datatable = source.Tables(1) 'assumes that the data is in the first
'table in the document
For i = 1 to 27
Set data = datatable.Cells(1, i).Range
data.End = data.End - 1
ff = "text" & i
target.FormFields(ff).Result = data
Next i

This assumes that the formfields have the following bookmark names assigned
to them - text1, text2, text3, .... text27

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 

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

Back
Top