Word Macros

Please support our Computer Science advertiser: Learn about neural networks and artificial intelligence.
Reply

Join Date: Aug 2007
Posts: 2
Reputation: webologix is an unknown quantity at this point 
Solved Threads: 0
webologix's Avatar
webologix webologix is offline Offline
Newbie Poster

Word Macros

 
0
  #1
Aug 13th, 2007
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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 160
Reputation: kb.net is an unknown quantity at this point 
Solved Threads: 26
kb.net's Avatar
kb.net kb.net is offline Offline
Junior Poster

Re: Word Macros

 
0
  #2
Aug 16th, 2007
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 2
Reputation: webologix is an unknown quantity at this point 
Solved Threads: 0
webologix's Avatar
webologix webologix is offline Offline
Newbie Poster

Re: Word Macros

 
0
  #3
Aug 16th, 2007
Thank you, I will try this. If you need any help with design, I'll be around...

Originally Posted by kb.net View Post
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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Computer Science Forum
Thread Tools Search this Thread



Tag cloud for Computer Science
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC