Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 65
Default Check if a workbook has an "open password"

Can I check if the workbooks in a folder have a password to open.

I actually want to display a message saying that "abc.xls is protected" if
abc.xls has a password to open.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Check if a workbook has an "open password"

On Apr 21, 6:28 am, Amit wrote:
Can I check if the workbooks in a folder have a password to open.

I actually want to display a message saying that "abc.xls is protected" if
abc.xls has a password to open.


Good evening Amit,
You can use the following function to detect if a file is password
protected:

Function fn_IsPassWordProtected(strWbk As String) As Boolean
Dim cn As Object

Set cn = CreateObject("ADODB.Connection")

On Error Resume Next
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=" & strWbk & "; Extended
Properties=Excel 8.0;"
.Open
If Err.Number < 0 Then
If Err.Number = "-2147467259" & Err.Description = "Could
not decrypt file." Then
fn_IsPassWordProtected = True
End If
End If
.Close
End With
On Error GoTo 0

Set cn = Nothing
End Function


You can test this in the immediate window on a couple of files with
the following snippet:
?fn_IsPassWordProtected(application.GetOpenFilenam e("Excel Files
(*.xls),*.xls"))

I've tested this function on several password/non-protected files and
all password-protected files were able to raise that error and
description...but test it for additional scenarios which may have been
overlooked.

Have a good weekend,


Ray R. Gable, Jr.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Password-Protected Workbook not showing "in use by another user" Jim Jackson Excel Discussion (Misc queries) 1 July 13th 06 03:11 PM
create links to check boxes marked "good" fair"and "bad" pjb Excel Worksheet Functions 3 April 20th 06 02:17 AM
"Password to Open" Secure? Jim Bennett Excel Discussion (Misc queries) 0 April 5th 06 04:53 PM
Problem: Worksheets("New Style 2006").Unprotect Password:="naPrint" Karoo News[_2_] Excel Programming 1 January 30th 06 02:40 PM


All times are GMT +1. The time now is 03:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"