PC Review


Reply
Thread Tools Rate Thread

Check if a workbook has an "open password"

 
 
=?Utf-8?B?QW1pdA==?=
Guest
Posts: n/a
 
      21st Apr 2007
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.
 
Reply With Quote
 
 
 
 
rgablejr@gmail.com
Guest
Posts: n/a
 
      22nd Apr 2007
On Apr 21, 6:28 am, Amit <A...@discussions.microsoft.com> 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.GetOpenFilename("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 With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Macros Run In "This Workbook" vs "All Open Workbooks" Janet Panighetti Microsoft Excel Discussion 1 11th Oct 2008 08:44 PM
Possible to change default "All Open Workbooks" to "This Workbook" in macro dialogue box? StargateFanFromWork Microsoft Excel Discussion 0 4th Jan 2006 10:49 PM
Check AD password if "user must change password next login" Oleg Ogurok Microsoft Dot NET Framework 1 23rd Jul 2004 07:06 PM
Window reports "Cannot open volume for direct access" when I have windows check drive "C:\" on boot..........HELP!! Dunny Rummy Windows XP Help 2 16th Jul 2004 10:38 PM
method "open" of object "workbook" failed Paul Hewson Microsoft Excel Misc 0 4th Aug 2003 11:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:33 AM.