Code Error help please?

A

Angyl

here's the code:

Dim rownum As Integer, i As Integer

ActiveDocument.Unprotect

ActiveDocument.Tables(1).Rows.Add

rownum = ActiveDocument.Tables(1).Rows.Count

For i = 1 To ActiveDocument.Tables(1).Columns.Count

ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput

Next i

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select

ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
~~~~~~

The error is "Compile Error" Expected: expression and it highlights the ":="
of
Range:=ActiveDocument

How do I fix that?
 
J

Jay Freedman

All of this should be on one line:

ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput

If you have it on three lines, either delete the carriage returns to
put it all together on the same line, or insert a space and an
underscore at the ends of th first two lines -- that's the
continuation indicator
(http://www.word.mvps.org/FAQs/MacrosVBA/_AtEndOfLine.htm).

Then do the same with these three lines:

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro=
"addrow"

and combine these two:

ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
A

Angyl

THANK YOU THANK YOU THANK YOU!!!

One more question for this project, please?

These fields that the macro is attached to perform a calculation based on
other form fields in the document such as =(Text1)*(Text2)

How could I go about attaching that calculation (along with the macro, as it
is already doing) to the new fields being created?
 
J

Jay Freedman

THANK YOU THANK YOU THANK YOU!!!

You're welcome.
One more question for this project, please?

These fields that the macro is attached to perform a calculation based on
other form fields in the document such as =(Text1)*(Text2)

How could I go about attaching that calculation (along with the macro, as it
is already doing) to the new fields being created?

It looks like Greg got you started in the right direction.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 

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