I have this add-ins that can protect and unprotect a word document, my problem is when I copy the file to the C:\Users\username\AppData\Roaming\Microsoft\Word\S TARTUP, It supposed to run in start up of word. but the thing is its not, its file extension is *.dotm. when I run/open the file the add-ins is running fine,it is showing in the document. that is why I think its working. All is fine with my word settings because i tried to add some add-ins and its working i mean its showing.
Here is my code for Add-ins
Code:
Private Sub Document_Open()
Call AddInView
End Sub
Private Sub AddInView()
Const strMenName As String = "PW Protection"
Dim cCurrBar As CommandBar
Dim cExtraMenu As CommandBarControl
Dim cAddInnPopup As CommandBarPopup
Dim cMenItem01 As CommandBarControl, cMenItem02 As CommandBarControl
Dim iStart As Integer, iEnd As Integer
Dim cMenItem01a As CommandBarControl, cMenItem01b As CommandBarControl
iEnd = Application.CommandBars(1).Controls.Count
For iStart = 1 To iEnd
If Application.CommandBars(1).Controls(iStart).Caption = strMenName Then Exit Sub
Next iStart
Set cCurrBar = Application.CommandBars.ActiveMenuBar
Set cExtraMenu = cCurrBar.Controls.Add(Type:=msoControlPopup, Temporary:=True, Before:=8)
cExtraMenu.Caption = strMenName
Set cMenItem01 = cExtraMenu.Controls.Add(Type:=msoControlButton)
With cMenItem01
.Caption = "Protect Document"
.OnAction = "ProtectDocument"
End With
Set cMenItem02 = cExtraMenu.Controls.Add(Type:=msoControlButton)
With cMenItem02
.Caption = "Unprotect Document"
.OnAction = "UnProtectDocument"
End With
End Sub
And here is my code for the protect and unprotect macro which will be call in add-ins
Code:
Sub ProtectDocument()
Dim Pwd As String
If ActiveDocument.ProtectionType = wdNoProtection Then
Pwd = InputBox("Enter your password to protect the document", "Password Input")
ActiveDocument.Protect NoReset:=True, _
Password:=Pwd, _
Type:=wdAllowOnlyReading
Else
MsgBox "Document is Protected"
End If
End Sub
Sub UnProtectDocument()
Dim Pwd As String
On Error GoTo ProtectNoResetErr
If ActiveDocument.ProtectionType <> wdNoProtection Then
Pwd = InputBox("Enter your password to unprotect the document", "Password Input")
' Unprotect the document.
ActiveDocument.Unprotect Password:=Pwd
Else
MsgBox "Document is UnProtected"
End If
ProtectNoResetErr:
If Err <> 0 Then MsgBox Err.Description
End Sub
Bookmarks