0

Can I find an answer here about a Word Macro issue? I am trying to apply a macro to a Protected Form document. The user will click on a button to "Add a new Activity" table, which is saved in annother file to be inserted using the macro. But when I apply the macro, this message appears: "Run-time error '4605' The object refers to a Protected document..." I found this code in some forum, but don't know how to configure to make my macro work...

Sub User_name()
' Macro by JanOSX
'
Dim nameStr As String, bName As String
Dim bookNum As Integer
nameStr = Environ("USERNAME")

bookNum = Selection.BookmarkID
ActiveDocument.Sections(2).ProtectedForForms = False
ActiveDocument.FormFields(bookNum).Select
Selection.TypeText (nameStr)
ActiveDocument.Sections(2).ProtectedForForms = True

End Sub

Anyone know how to program Word macros?

2
Contributors
2
Replies
3
Views
10 Years
Discussion Span
Last Post by webologix
0

Hi,

If you want to unprotect a document copy a selection from another document, paste in the unprotected form, and reprotect, use the below sub:

Sub CopyProt()

    Windows("Doc2.doc").Activate
    Selection.Copy
    
    Windows("Doc1.doc").Activate
    ActiveDocument.Protect wdNoProtection
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.PasteAndFormat (wdPasteDefault)
    ActiveDocument.Protect wdAllowOnlyFormFields
    
End Sub
0

Thank you, I will try this. If you need any help with design, I'll be around...

Hi,

If you want to unprotect a document copy a selection from another document, paste in the unprotected form, and reprotect, use the below sub:

Sub CopyProt()

    Windows("Doc2.doc").Activate
    Selection.Copy
    
    Windows("Doc1.doc").Activate
    ActiveDocument.Protect wdNoProtection
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.PasteAndFormat (wdPasteDefault)
    ActiveDocument.Protect wdAllowOnlyFormFields
    
End Sub
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.