Auto password protecting words file from excel

badsham77

New Member
Joined
May 4, 2011
Messages
10
Hi,

I'm trying to do a VB command which will auto password protecting Words file from a list in Excel.
The command goes like this:

Sub wordpsword()
Dim docOne(1 To 300) As Document, i As Long, j As Long
With ThisWorkbook
For i = 5 To 300
If .Worksheets("Sheet1").Range("B" & i).Value <> "" And .Worksheets("Sheet1").Range("C" & i).Value <> "" Then
j = j + 1
Set docOne(j) = Documents.Open(.Worksheets("Sheet1").Range("B" & i).Value & .Worksheets("Sheet1").Range("C" & i).Value)
Application.DisplayAlerts = False
docOne(j).SaveAs Filename:=.Worksheets("Sheet1").Range("B" & i).Value & .Worksheets("Sheet1").Range("C" & i).Value, Password:=.Worksheets("Sheet1").Range("D" & i).Value
'Where "B" is the file path, "C" is the file name, and "D" is the password to use.
docOne(j).Close
Application.DisplayAlerts = True
End If

Next i
End With
MsgBox j & "Files Protected", vbInformation
End Sub

When I run this command there is an error message says Run-time error '429':
ActiveX component can't create object

What is wrong with this? Can somebody help.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

Forum statistics

Threads
1,224,504
Messages
6,179,144
Members
452,891
Latest member
JUSTOUTOFMYREACH

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top