If则取消保护和保护文档



我有一个用户表单,它取消对文档的保护以允许输入信息,然后保护文档。我所有的潜艇都只工作一个。

带有if/then的范围不起作用,但是基本的if then可以。

子元素的例子:

Private Sub ComboBox5_Change()
ActiveDocument.Unprotect "password"
Dim ComboBox5 As Range
Set ComboBox5 = ActiveDocument.Bookmarks("bmragpd").Range
ComboBox5.Text = Me.ComboBox5.Value

If Me.ComboBox5.Value = "No" Then
ComboBox5.Text = "205.55a"
End If

If Me.ComboBox5.Value = "Yes" Then
ComboBox5.Text = ""
End If
ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:="password"
End Sub

此子文件将说明该文档已未受保护。

我尝试删除combobox6上的unprotect:

Private Sub ComboBox6_Change()
ActiveDocument.Unprotect "password"
Dim rngComboBox6 As Range
Dim sssaText As String
Dim iiia As Integer
Set rngComboBox6 = ActiveDocument.Bookmarks("bmfcs").Range
sssaText = ComboBox6.Value
If Me.ComboBox6.Value = "Yes" Then
For iiia = 1 To 1
sssaText = sssaText & Chr(13) & "200" _
& Chr(13) & "200.1" _
& Chr(13) & "" _
& Chr(13) & "OEBS" _
& Chr(13) & "" _
& Chr(13) & "21c" _
& Chr(13) & "" _
& Chr(13) & "22c" _
& Chr(13) & "Yes" _
& Chr(13) & "" _
& Chr(13) & "Yes" _
& Chr(13) & "Two" _
& Chr(13) & "" _
& Chr(13) & "ES2a.1" _
& Chr(13) & "" _
& Chr(13) & "222" _
& Chr(13) & "" _
& Chr(13) & "222a" _
& Chr(13) & "222b" _
& Chr(13) & "" _
& Chr(13) & "3.a.1" _
& Chr(13) & "" _
& Chr(13) & "NA" _
& Chr(13) & "" _
& Chr(13) & "I. TuuVa"

Next iiia
sssaText = sssaText & Chr(13) & "717217" _
& Chr(13) & "" _
& Chr(13) & "1212" _
& Chr(13) & "" _
& Chr(13) & "D.1" _
& Chr(13) & "F2B-4"
End If

rngComboBox6.Text = sssaText
ActiveDocument.Bookmarks.Add "bmfcs", rngComboBox6

If Me.ComboBox6.Value = "No" Then
ComboBox6.Text = ""
End If

ActiveDocument.Protect wdAllowOnlyFormFields, NoReset:=True, Password:="password"
End Sub

第一个End If放错地方了。无论组合框的值如何,您都在向文档中添加文本。

使用控件的变更事件向文档提交变更不是一个好的实践。除此之外,它不允许用户在不进行更改的情况下取消。

使用OK/Apply/Finish按钮。

那么你只需要取消保护/重新保护文档一次。

最新更新