Question
I am working on a VBA Macro that will open multiple worksheets at a time per year with their respective passwords. For example, I have
I am working on a VBA Macro that will open multiple worksheets at a time per year with their respective passwords. For example, I have folders for years 2005-2011 that contain files, where some files have password protection, and it is a different password per file. I need to be able to open those files back to back without entering the passwords manually every time. Here is what I have so far:
Sub Magic()
Dim i As Long, wb As Workbook, bOpen As Boolean, fName As String, year As Integer On Error Resume Next 'turn error reporting off
Dim myArray(14 To 20) As String
myArray(14) = "lila" myArray(15) = "boss" myArray(16) = "slip" myArray(17) = "pogo" myArray(18) = "duck" myArray(19) = "wash" myArray(20) = "guru"
year = 2005
Do While year < 2012
directory = "I:\ICRAS\Papers & PKIS\" & year & "\PKI" & year & "\" fName = Dir(directory & "*.xl??") For i = LBound(myArray) To UBound(myArray) Set wb = Workbooks.Open(fName, WriteResPassword:=myArray(i)) If Not wb Is Nothing Then bOpen = True: Exit For Next i On Error GoTo 0 'turn error reporting back on
If bOpen Then MsgBox "File was opened with password: " & myArray(i) Else MsgBox "Password not found for file!" End If
Loop End Sub
I keep getting syntax errors and I think it has to do with the Workbook.Open part. I appreciate the help.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started