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.
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.