Results 1 to 2 of 2
  1. #1
    2 Star Lounger
    Join Date
    Jul 2003
    Park City, Utah
    Thanked 0 Times in 0 Posts

    Protect Multiple Documents (2003-SP1)

    I use the following to print and move all the documents in a directory:

    Dim sMyDir As String
    Dim sDocName As String
    ' The path to obtain the files.
    sMyDir = "C:InetpubftprootPrint"
    sDocName = Dir(sMyDir & "*.DOC")
    If sDocName = "" Then GoTo LastLine
    While sDocName <> ""
    ' Print the file.
    Application.PrintOut Background:=False, FileName:=sMyDir & sDocName
    ' Get next file name.
    sDocName = Dir()
    Const strSource = "C:InetpubftprootPrint*.doc"
    Const strTarget = "C:InetpubftprootArchive"
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    fso.CopyFile strSource, strTarget
    fso.DeleteFile strSource
    Set fso = Nothing

    I need to do the same thing, only password protect each of the documents before moving them (no printing this time, so I would replace the line after the 'Print the file comment above). I recorded the following to password protect documents (and will insert the password in the actual code), but I know this works on an open document. How do I do it for each document in the directory:

    ActiveDocument.Protect Password:="", NoReset:=False, Type:= wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False

    Thanks again to you kind, thoughtful, brilliant minds out there!

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Thanked 28 Times in 28 Posts

    Re: Protect Multiple Documents (2003-SP1)

    I don't know if you need the part after Wend; I omitted it below, beut you can reinsert it. I changed the old-fashioned While ... Wend to the more modern Do While ... Loop.

    Sub ProtectDocs()
    Dim sMyDir As String
    Dim sDocName As String
    Dim doc As Document
    ' The path to obtain the files.
    sMyDir = "C:InetpubftprootPrint"
    sDocName = Dir(sMyDir & "*.doc")
    Do While sDocName <> ""
    ' Open the file.
    Set doc = Documents.Open(FileName:=sMyDir & sDocName)
    ' Set password
    doc.Protect Password:="secret", Type:=wdAllowOnlyReading, _
    UseIRM:=False, EnforceStyleLock:=False
    ' Close and save the document
    doc.Close SaveChanges:=wdSaveChanges
    ' Get next file name.
    sDocName = Dir()
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts