PDA

View Full Version : Allow userform entry on protected word document - MS Word 2010



april2201
10-13-2014, 02:18 AM
Hi,

I am new on VBA, I am struggling to use the right code where it will allow the userform entry on a protected word document.

I was successful on adding a customised toolbar where there is button to launch the Userform pop-up, but after adding restriction on the word document because I need to protect the document from any modifications, the userform entry are not applying to my formfields. It gives me the error message below after clicking the ‘OK’ button.

Run-time error ‘6124’
You are not allowed to edit this selection because it is protected.

Can someone help me what is the right code to add on my current code below? So it will allow the userform entry to my protected word document.


Option Explicit

Private Sub cmdCancel_Click()
Unload Me
ActiveDocument.Close SaveChanges:=False
End Sub

Private Sub cmdClear_Click()
txtbxTP.Value = Null
txtbxAgreeDate.Value = Null
txtbxAgreeRefno.Value = Null
txtbxCommDate.Value = Null
txtbxTermDate.Value = Null
txtbxSysApp1.Value = Null
txtbxSysApp2.Value = Null
txtbxSysApp3.Value = Null
txtbxfunc1.Value = Null
txtbxfunc2.Value = Null
txtbxfunc3.Value = Null
txtbxParent1.Value = Null
txtbxParent2.Value = Null
txtbxParent3.Value = Null
txtbxEKFullName.Value = Null
txtbxEKDesig.Value = Null
txtbxEKCompAdd.Value = Null
txtbxEKTel.Value = Null
txtbxEKEmail.Value = Null
txtbxTPFullName.Value = Null
txtbxTPDesig.Value = Null
txtbxTPCompAdd.Value = Null
txtbxTPTel.Value = Null
txtbxTPEmail.Value = Null
End Sub


Private Sub cmdOK_Click()
Dim strFrame1 As String
Application.ScreenUpdating = False

With ActiveDocument
.Bookmarks("thirdparty").Range.Text = txtbxTP.Value
.Bookmarks("agreedate").Range.Text = txtbxAgreeDate.Value
.Bookmarks("refnum").Range.Text = txtbxAgreeRefno.Value
.Bookmarks("commenceDate").Range.Text = txtbxCommDate.Value
.Bookmarks("terminateDate").Range.Text = txtbxTermDate.Value
.Bookmarks("sys1").Range.Text = txtbxSysApp1.Value
.Bookmarks("sys2").Range.Text = txtbxSysApp2.Value
.Bookmarks("sys3").Range.Text = txtbxSysApp3.Value
.Bookmarks("sys4").Range.Text = txtbxSysApp4.Value
.Bookmarks("sys5").Range.Text = txtbxSysApp5.Value
.Bookmarks("funct1").Range.Text = txtbxfunc1.Value
.Bookmarks("funct2").Range.Text = txtbxfunc2.Value
.Bookmarks("funct3").Range.Text = txtbxfunc3.Value
.Bookmarks("funct4").Range.Text = txtbxfunc4.Value
.Bookmarks("funct5").Range.Text = txtbxfunc5.Value
.Bookmarks("agree1").Range.Text = txtbxParent1.Value
.Bookmarks("agree2").Range.Text = txtbxParent2.Value
.Bookmarks("agree3").Range.Text = txtbxParent3.Value
.Bookmarks("agree4").Range.Text = txtbxParent4.Value
.Bookmarks("agree5").Range.Text = txtbxParent5.Value
.Bookmarks("EKname").Range.Text = txtbxEKFullName.Value
.Bookmarks("EKdesignation").Range.Text = txtbxEKDesig.Value
.Bookmarks("EKaddress").Range.Text = txtbxEKCompAdd.Value
.Bookmarks("EKphone").Range.Text = txtbxEKTel.Value
.Bookmarks("Ekemail").Range.Text = txtbxEKEmail.Value
.Bookmarks("TPname").Range.Text = txtbxTPFullName.Value
.Bookmarks("TPdesignation").Range.Text = txtbxTPDesig.Value
.Bookmarks("TPaddress").Range.Text = txtbxTPCompAdd.Value
.Bookmarks("TPphone").Range.Text = txtbxTPTel.Value
.Bookmarks("TPemail").Range.Text = txtbxTPEmail.Value

End With

Application.ScreenUpdating = True
Unload Me
End Sub

Private Sub UserForm_Initialize()
txtbxTP.Value = "Enter Third Party Name"


End Sub

gmayor
10-20-2014, 07:11 AM
I felt sure I had answered this elsewhere - https://social.msdn.microsoft.com/forums/ie/zh-tw/34425ab9-9c56-4a6c-82d5-ed1a8f8cef6c/allow-userform-entry-in-a-protected-word-document-ms-word-2010?forum=isvvba (https://social.msdn.microsoft.com/forums/ie/zh-tw/34425ab9-9c56-4a6c-82d5-ed1a8f8cef6c/allow-userform-entry-in-a-protected-word-document-ms-word-2010?forum=isvvba)