Hi pedro,
You could use an 'on exit' macro like the following attached to a formfield:
Sub UpdateDoc()
Dim ToC As TableOfContents
Dim pRange As Word.Range
Dim Pwd As String
Dim pState As Boolean
With ActiveDocument
pState = False
If .ProtectionType <> wdNoProtection Then
Pwd = InputBox("PleasePassword", "Password")
pState = True
.Unprotect Pwd
End If
' Loop through Story Ranges and update.
' Note that this may trigger interactive fields (eg ASK and FILLIN).
For Each pRange In .StoryRanges
Do
pRange.Fields.Update
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
' Loop through Tables Of Contents and update
For Each ToC In .TablesOfContents
ToC.Update
Next
If pState = True Then .Protect wdAllowOnlyFormFields, Noreset:=True, Password:=Pwd
pState = False
Pwd = ""
End With
End Sub
The code asks the use to input the password. If you don't want to do that, replace:
Pwd = InputBox("PleasePassword", "Password")
with:
Pwd = "Password"
where "Password" is the actual password.
Note that the macro includes code to update the ToC also, since it's difficult to get ToCs to update correctly in a form. The same
applies to Tables of Authorities and Tables of Figures, but you haven't mentioned the document having any of them. You can delete
the code to update the ToC if none of your formfields can change the document's pagination.
Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
Hi pedro,
Formula Correction:
{={DropDown1}+{DropDown2}+{DropDown3}+{DropDown4}+{DropDown5}+{DropDown6}+{DropDown7}}
Cheers
--
macropod
[MVP - Microsoft Word]
-------------------------
macropod said:
You don't need a macro to do the calculation. All you need is a formula field (not a formfield), coded as:
{=DropDown1+DropDown2+DropDown3+DropDown4+DropDown5+DropDown6+DropDown7}
where the field braces (ie '{ }') are created via Ctrl-F9.
As for the TOC, the best way to update it in a form is to use a macro to temporarily unprotect the form, update the TOC, then
reprotect the form (with noreset = true).
"pedro gracio" wrote in messagenews:
[email protected]...
- Show quoted text -
Hi macropod,
Sorry for re-posting, I did not see your reply...
How would I create a "macro to temporarily unprotect the form" ?
The other thing that I tried and it worked great until I placed the
table in a document with a TOC is just using a regular Text Form Field
type Number with the calculate on exit, and in the last cell I used
the formula "=SUM(d2:d21)". This again woked just fine, it calculated
automatically & all but once there is a TOC it didn't do anything...
pedy