Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending password to Excel Object

Status
Not open for further replies.

TimGoff

Technical User
Jul 16, 2002
166
GB
Hi,

I'm opening up a password protected spreadsheet from an Outlook form. All is fine apart from the code falls over when trying to send the password in the code. If you remove the password:="password" it works fine.

Anybody any ideas?
Thanks
Tim

Function fCheckAuthorisation(strNameToAuthorise)
Dim objExcel
Dim strFilePath
Dim strFileName
Dim intExcelRow
Dim intExcelColumn
Dim intLoopValue
Dim strName

fCheckAuthorisation = False

strFilePath = ("c:\")
strFileName = ("approval.xls")

Set objExcel = CreateObject("Excel.Application.10")

objExcel.Workbooks.Open strFilePath & strFileName, Password:=("password")

intExcelRow = 1
intExcelColumn = 1

strName = objExcel.Application.Cells(intExcelRow, intExcelColumn)

Do Until strName = ""
strName = objExcel.Application.Cells(intExcelRow, intExcelColumn)
If strName = strNameToAuthorise Then
fCheckAuthorisation = True
Exit Do
End If
intExcelRow = intExcelRow + 1
intLoopValue = intLoopValue + 1
Loop

objExcel.Quit
Set objExcel = Nothing
End Function
 
If it's the Open Workbook password, use

objExcel.Workbooks.Open strFileName,,,,"Password"

If it's the Write Reserved password, use

objExcel.Workbooks.Open strFileName,,,,,"Password"

FYI, this is for Excel 2K, you appear to be using Excel XP. It may vary, but I'm not using XP yet. Jon Hawkins
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top