Go Back   Access World Forums > Apps and Windows > Word

 
Reply
 
Thread Tools Rate Thread Display Modes
Old 06-07-2017, 11:56 PM   #1
Rewly
Newly Registered User
 
Join Date: Jun 2017
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Rewly is on a distinguished road
batch set the password for word documents

Hi.

I have quite a few word files and I want to set the password for them all to protect them.

Do I have to set the password one by one? Any way to batch set the password for several word documents?

Rewly is offline   Reply With Quote
Old 06-08-2017, 12:40 AM   #2
Ranman256
Newly Registered User
 
Join Date: Apr 2015
Location: KY,USA
Posts: 3,287
Thanks: 0
Thanked 720 Times in 705 Posts
Ranman256 will become famous soon enough Ranman256 will become famous soon enough
Re: batch set the password for word documents

in word VBE, paste the code below into a module.
then call it with

ScanFilesInDir "C:\Users\user\documents"

it will scan all .doc or .docX and save them with a password.

BE SURE TO REPLACE YOUR PASSWORD BELOW IN THE CODE


Code:
'---------------
Public Sub ScanFilesInDir(ByVal pvDir)
'---------------
Dim fso
Dim oFolder, oFile
Dim vName, vSrc

On Error GoTo errImp

If Right(pvDir, 1) <> "\" Then pvDir = pvDir & "\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set oFolder = fso.GetFolder(pvDir)

For Each oFile In oFolder.Files
    vFil = pvDir & oFile.Name

    If InStr(vFil, ".doc") > 0 And InStr(vFil, pvID) > 0 Then       'ONLY DO .doc files
           vSrc = pvDir & oFile.Name
           'MsgBox vSrc

        Documents.Open vSrc
        vName = ActiveDocument.Name
        'MsgBox vName
        ActiveDocument.SaveAs vName, Password:="password" 
        ActiveDocument.Close False
    End If
Next

Set fso = Nothing
Set oFile = Nothing
Set oFolder = Nothing
Exit Sub

errImp:
MsgBox Err.Description, vbCritical, "clsImport:ImportData()" & Err
Exit Sub
Resume
End Sub
Ranman256 is offline   Reply With Quote
The Following User Says Thank You to Ranman256 For This Useful Post:
Rewly (06-14-2017)
Old 06-08-2017, 01:43 AM   #3
isladogs
Part time moderator
 
isladogs's Avatar
 
Join Date: Jan 2017
Location: Somerset, UK
Posts: 8,625
Thanks: 102
Thanked 2,275 Times in 2,097 Posts
isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all isladogs is a name known to all
Re: batch set the password for word documents

That's a nice bit of code and may be useful to me as well
Thanks

__________________
If this answer has helped, please click the Thanks button and/or click the 'reputation scales' symbol on the left.

Website links:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.


Colin
Access 2010 32-bit, Access 2016 32-bit & 64-bit, SQL Server Express 2014, Windows 10,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
,
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
isladogs is offline   Reply With Quote
Old 06-12-2017, 07:08 PM   #4
Lsudls
Newly Registered User
 
Join Date: Jun 2017
Posts: 1
Thanks: 0
Thanked 1 Time in 1 Post
Lsudls is on a distinguished road
Re: batch set the password for word documents

Hi,

As have mentioned above, You can use VBA codes.

1.Prevent Multiple Documents from Opening

Quote:
Sub ProtectMultiDocWithOpenPassword()
Dim objDoc As Document
Dim strPassword As String, strFile As String, strFolder As String

strPassword = "123"
strFolder = "E:\Temp\test"
strFile = Dir(strFolder & "*.docx", vbNormal)

While strFile <> ""
Set objDoc = Documents.Open(FileName:=strFolder & strFile)

With objDoc
.Password = strPassword
.SaveAs2 FileName:=objDoc.FullName, Password:=strPassword
.Close
End With
strFile = Dir()
Wend
End Sub
2.Prevent Multiple Documents from Editing

Quote:
Sub ProtectMultiDocWithEditPassword()
Dim objDoc As Document
Dim strPassword As String, strFile As String, strFolder As String

Set objDoc = ActiveDocument
strPassword = "456"
strFolder = "C:\Users\Public\Documents\New folder"
strFile = Dir(strFolder & "*.docx", vbNormal)

While strFile <> ""
Set objDoc = Documents.Open(FileName:=strFolder & strFile)

objDoc.Protect Password:=strPassword, NoReset:=False, Type:= _
wdAllowOnlyReading, UseIRM:=False, EnforceStyleLock:=False
objDoc.Save
objDoc.Close
strFile = Dir()
Wend
End Sub
You can search the article on google:

"How to Quickly Protect a Batch of Word Documents with Password"

Good luck.
Lsudls is offline   Reply With Quote
The Following User Says Thank You to Lsudls For This Useful Post:
Rewly (06-14-2017)
Old 06-14-2017, 05:59 PM   #5
Rewly
Newly Registered User
 
Join Date: Jun 2017
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Rewly is on a distinguished road
Re: batch set the password for word documents

Thanks for all help! The macros are amazing!

Rewly is offline   Reply With Quote
Reply

Tags
word 2010

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Batch Process to Open Password Protected Access Db pgraju General 1 03-04-2008 06:08 PM
Attach Word Documents, PDF eidolon74 Modules & VBA 1 01-15-2007 06:45 PM
Passing DB Password w/ Batch File irini General 0 07-09-2003 06:02 AM
Inserting Word Documents niall Reports 1 12-19-2002 02:02 AM
Hyperlinking Word documents Rod C Modules & VBA 1 02-11-2002 05:22 PM




All times are GMT -8. The time now is 04:23 PM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Featured Forum post


Sponsored Links


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World