Re: Macro generates runtime error



No wonder you are getting error messages. You are adding to tables. Your
code is not set to change any values of form fields. You can't do this while
the document is protected.

What you are talking about is what Word calls an "online form." For more
about online forms, follow the links at
http://addbalance.com/word/wordwebresources.htm#Forms or
http://word.mvps.org/FAQs/Customization/FillinTheBlanks.htm especially Dian
Chapman's series of articles. I strongly recommend that you work through all
of Dian Chapman's articles. They give examples of manipulating online forms
with code.

Hope this helps,
--

Charles Kenyon

Word New User FAQ & Web Directory: http://addbalance.com/word

Intermediate User's Guide to Microsoft Word (supplemented version of
Microsoft's Legal Users' Guide) http://addbalance.com/usersguide

See also the MVP FAQ: http://word.mvps.org/FAQs/ which is awesome!

My criminal defense site: http://addbalance.com
--------- --------- --------- --------- --------- ---------
This message is posted to a newsgroup. Please post replies
and questions to the newsgroup so that others can learn
from my ignorance and your wisdom.
"QDE" <QDE@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:398F1855-865D-413A-A82C-E111F1FB5CBF@xxxxxxxxxxxxxxxx
Here's the error message: "Run-time error '6124': You are not allowed to
edit this region because document protection is in effect." The document
is
protected only for forms and the fields are all form fields that allow
data
entry. Input is accepted in all fields except those involved in the
macro,
which still runs without errors in all earlier versions of Word.

Here's the macro code:

Sub TableFormula()
' Calculate and display totals for Table 5.
Dim cLabor1Cell As Cell
Dim cLabor2Cell As Cell
Dim cBurden1Cell As Cell
Dim cBurden2Cell As Cell
Dim cMaterial1Cell As Cell
Dim cMaterial2Cell As Cell
Dim cTotal1Cell As Cell
Dim cTotal2Cell As Cell
Dim cCell1Total As Currency
Dim cCell2Total As Currency
' Set variables equal to specified cells.
Set cLabor1Cell = ActiveDocument.Tables(5).Cell(Row:=5, Column:=2)
Set cLabor2Cell = ActiveDocument.Tables(5).Cell(Row:=5, Column:=4)
Set cBurden1Cell = ActiveDocument.Tables(5).Cell(Row:=6, Column:=2)
Set cBurden2Cell = ActiveDocument.Tables(5).Cell(Row:=6, Column:=4)
Set cMaterial1Cell = ActiveDocument.Tables(5).Cell(Row:=7, Column:=2)
Set cMaterial2Cell = ActiveDocument.Tables(5).Cell(Row:=7, Column:=4)
Set cTotal1Cell = ActiveDocument.Tables(5).Cell(Row:=8, Column:=2)
Set cTotal2Cell = ActiveDocument.Tables(5).Cell(Row:=8, Column:=4)
' Calculate totals
cCell1Total = Val(cLabor1Cell.Range.Text) + Val(cBurden1Cell.Range.Text)
+ Val(cMaterial1Cell.Range.Text)
cCell2Total = Val(cLabor2Cell.Range.Text) + Val(cBurden2Cell.Range.Text)
+ Val(cMaterial2Cell.Range.Text)
' Insert results of calculations into cells C8 and E8 of Table 5.
If cCell1Total > 0 Then
cTotal1Cell.Range.Text = Format(cCell1Total, "######.00")
Else
cTotal1Cell.Range.Text = ""
End If
If cCell2Total > 0 Then
cTotal2Cell.Range.Text = Format(cCell2Total, "######.00")
Else
cTotal2Cell.Range.Text = ""
End If
End Sub

"Jay Freedman" wrote:

Insufficient information. Please post the code of the macro, and the
exact wording of the error message. I can't promise that a diagnosis
will be possible with that information, but it's impossible without
it.

In the meantime, check that every field named in the macro actually
exists with exactly the same name in the form.

--
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.

On Sat, 29 Apr 2006 09:44:01 -0700, QDE
<QDE@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

For ages I have been using a protected form that I created in Word 2000
which
uses a simple macro to add numbers entered in form fields, update a
total,
and display the total in a form field. After the upgrade to Word 2003
every
field involved in the macro causes a VB runtime error. I've changed to
"low"
security and the macro still won't run on computers that have been
upgraded
to 2003. Any suggestions?



.