S
spunkymuffmonkey
Hi everyone.
I have hit a problem with a protected form I'm working with.
I have a macro that allows users to add a new row to a table within the
protected form, the macro adds formfields in to the new row, one of which is
a calculation field.
This calcuation field simply multiplies the previous two fields contents
using cell references (i.e. b1 * c1, however this unfortunately does not seem
to work when the form is reprotected and contents entered into b1/c1 etc.
I have checked the expression that I am generating to the new field, and
that calculate on exit is set to true, but no joy.
The funny thing is that when I unlock the form then check the calcualtion
field properties, and then click OK, the calculation field displays the right
result.
Below is the code I'm using, any help would be greatly appreciated.
Private Sub CommandButton1_Click()
Dim oTable As Table
Dim sPassword, sDefault As String
Dim iRowCount As Integer
Application.ScreenUpdating = False
sPassword = "Gatekeeper1"
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect sPassword
End If
End With
Set oTable = ActiveDocument.Tables(6)
oTable.Rows.Add
iRow = oTable.Rows.Count
oTable.Cell(iRow, 1).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 1).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 2).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 2).Select
With Selection.FormFields(1)
.CalculateOnExit = True
With .TextInput
.EditType wdNumberText, Format:="0"
End With
End With
oTable.Cell(iRow, 3).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 3).Select
With Selection.FormFields(1)
.ExitMacro = "UpdateField"
.CalculateOnExit = True
With .TextInput
.EditType wdNumberText, Format:="0"
End With
End With
oTable.Cell(iRow, 4).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 4).Select
iRowCount = oTable.Rows.Count
sDefault = "=b" & iRowCount & "*" & "c" & iRowCount
With Selection.FormFields(1)
.TextInput.EditType Type:=wdCalculationText, Format:="",
Enabled:=False
.CalculateOnExit = True
.TextInput.Default = sDefault
End With
oTable.Cell(iRow, 5).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 5).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 6).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 6).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 7).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 7).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="Title Case"
End With
End With
oTable.Cell(iRow, 1).Select
Unload Me
ActiveDocument.Protect wdAllowOnlyFormFields, Password:=sPassword,
noreset:=True
Application.ScreenUpdating = True
End Sub
I have hit a problem with a protected form I'm working with.
I have a macro that allows users to add a new row to a table within the
protected form, the macro adds formfields in to the new row, one of which is
a calculation field.
This calcuation field simply multiplies the previous two fields contents
using cell references (i.e. b1 * c1, however this unfortunately does not seem
to work when the form is reprotected and contents entered into b1/c1 etc.
I have checked the expression that I am generating to the new field, and
that calculate on exit is set to true, but no joy.
The funny thing is that when I unlock the form then check the calcualtion
field properties, and then click OK, the calculation field displays the right
result.
Below is the code I'm using, any help would be greatly appreciated.
Private Sub CommandButton1_Click()
Dim oTable As Table
Dim sPassword, sDefault As String
Dim iRowCount As Integer
Application.ScreenUpdating = False
sPassword = "Gatekeeper1"
With ActiveDocument
If .ProtectionType <> wdNoProtection Then
.Unprotect sPassword
End If
End With
Set oTable = ActiveDocument.Tables(6)
oTable.Rows.Add
iRow = oTable.Rows.Count
oTable.Cell(iRow, 1).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 1).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 2).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 2).Select
With Selection.FormFields(1)
.CalculateOnExit = True
With .TextInput
.EditType wdNumberText, Format:="0"
End With
End With
oTable.Cell(iRow, 3).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 3).Select
With Selection.FormFields(1)
.ExitMacro = "UpdateField"
.CalculateOnExit = True
With .TextInput
.EditType wdNumberText, Format:="0"
End With
End With
oTable.Cell(iRow, 4).Select
Selection.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormTextInput
oTable.Cell(iRow, 4).Select
iRowCount = oTable.Rows.Count
sDefault = "=b" & iRowCount & "*" & "c" & iRowCount
With Selection.FormFields(1)
.TextInput.EditType Type:=wdCalculationText, Format:="",
Enabled:=False
.CalculateOnExit = True
.TextInput.Default = sDefault
End With
oTable.Cell(iRow, 5).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 5).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 6).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 6).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="First capital"
End With
End With
oTable.Cell(iRow, 7).Select
Selection.FormFields.Add Range:=Selection.Range,
Type:=wdFieldFormTextInput
oTable.Cell(iRow, 7).Select
With Selection.FormFields(1)
With .TextInput
.EditType wdRegularText, Format:="Title Case"
End With
End With
oTable.Cell(iRow, 1).Select
Unload Me
ActiveDocument.Protect wdAllowOnlyFormFields, Password:=sPassword,
noreset:=True
Application.ScreenUpdating = True
End Sub