943,834 Members | Top Members by Rank

Ad:
Aug 13th, 2007
0

Word Macros

Expand Post »
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?
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
webologix is offline Offline
2 posts
since Aug 2007
Aug 16th, 2007
0

Re: Word Macros

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
Reputation Points: 13
Solved Threads: 29
Junior Poster
kb.net is offline Offline
169 posts
since Aug 2007
Aug 16th, 2007
0

Re: Word Macros

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

Click to Expand / Collapse  Quote originally posted by kb.net ...
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
webologix is offline Offline
2 posts
since Aug 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Computer Science Forum Timeline: Word datatype values
Next Thread in Computer Science Forum Timeline: Complexity of an algorithm





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC