WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Samples from Users

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Determine if XLS File is Password Protected

 Keywords: Protected Password Excel XLS XLSX HasPassword

filename = "D:\temp\Data\Book1.xlsx" ;spreadsheet without password
;filename="D:\temp\Data\Password.xlsx" ;spreadsheet with password

; Access the Excel Object Model
objApp = ObjectCreate( 'Excel.Application' )

; Defines some display properites
objApp.Visible = @FALSE     ; hides the window
objApp.UserControl = @TRUE
objApp.DisplayAlerts = @FALSE

; Attempt to open the workbook using a fake password
ErrorMode(@OFF) ; Supress error for a single statment
objXlWb = objApp.Workbooks.Open(:: FileName=filename, Password="DUMMYPASSWORD")
ErrorMode(@CANCEL); Reset error handling

; If operation fails, then assume its a password protected file
If objXlWb == 0
   Pause("","Has password!")
Else
   Pause("","No password!")
EndIf

; Close the workbook
objApp.Workbooks.Close()
; Quit Excel
objApp.Quit
; Close object handle
objApp = 0
Exit

Article ID:   W18118
Filename:   Determine if XLS File is Password Protected .txt
File Created: 2010:10:04:14:40:48
Last Updated: 2010:10:04:14:40:48