Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / May 2006

Tip: Looking for answers? Try searching our database.

Code Error help please?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Angyl - 10 May 2006 02:46 GMT
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?
Jay Freedman - 10 May 2006 04:17 GMT
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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>here's the code:
>
[quoted text clipped - 29 lines]
>
>How do I fix that?
Angyl - 10 May 2006 04:57 GMT
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?
Jay Freedman - 11 May 2006 03:16 GMT
>THANK YOU THANK YOU THANK YOU!!!

You're welcome.

>One more question for this project, please?
>
[quoted text clipped - 3 lines]
>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        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.