View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default Bypassing password protection in Visual Basic

Hi Matt,

Perhaps we need to clarify what you refer to as a worksheet.

A worksheet is one of the tabs (worksheets) within a workbook containing a
collection of worksheets. A workbook is actually the file that is saved and
you open. I suspect that you mean a workbook; not a worksheet.

If the above is correct, do you have the passwords for the individual
workbooks? If not, you need to get them.

The following example code opens workbooks with passwords.

Sub OpenWithPassword()
Dim strpath As String
Dim strPathNfile As String
Dim wb As Workbook

'Options for setting path
strpath = ThisWorkbook.Path & "\"
'strpath = "C:\OssieMac\Documents\Excel\"

'Variable with full path and filename
strPathNfile = strpath & "Test workbook with password.xls"

'Open the workbook with password
Workbooks.Open Filename:=strPathNfile, _
Password:="mypassword"

'Open the workbook including WriteResPassword
'Workbooks.Open Filename:=strPathNfile, _
Password:="mypassword", WriteResPassword:="mypassword"

Set wb = ActiveWorkbook

End Sub


Following from a post by Tom Ogilvy MVP

Note that there are two types of password arguments:

Password Optional Variant. A string that contains the password required to
open a protected workbook. If this argument is omitted and the workbook
requires a password, the user is prompted for the password.

WriteResPassword Optional Variant. A string that contains the password
required to write to a write-reserved workbook. If this argument is omitted
and the workbook requires a password, the user will be prompted for the
password.

--
Regards,

OssieMac