Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Rob Oldfield
 
Posts: n/a
Default Automate response to protected files

I'm attempting (via automation from .Net) to scroll through a list of Excel
files and do something (which is immaterial to this question) with those
files.

That is working - until I get to a file which is password protected where
when I try to open the file it pops up the password box and stops my code.
Is there a property of the workbook that I can grab that says "this is
protected" so that I can skip that file?



  #2   Report Post  
Dave Peterson
 
Posts: n/a
Default

First, I don't know anything about .Net.

But excel is pretty interesting.

If you try to open a non-protected workbook via code, it won't care if you try
with a bad password. If the workbook is protected, the workbook won't open --
but you won't get prompted.

For instance:

Option Explicit
Sub testme()
Dim wkbk As Workbook
Dim myList As Variant
Dim bCtr As Long
Dim myPath As String

myPath = "C:\my documents\excel\"
myList = Array("book2.xls", "book1.xls", "book3.xls")

For bCtr = LBound(myList) To UBound(myList)
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=myPath & myList(bCtr), _
ReadOnly:=True, Password:="xxx")
On Error GoTo 0

If wkbk Is Nothing Then
MsgBox "either missing or wrong password: " & myPath & myList(bCtr)
Else
wkbk.Close savechanges:=False
End If
Next bCtr

End Sub

I could even use: password:=""
in that .open statement if I were afraid of guessing the correct password.


Rob Oldfield wrote:

I'm attempting (via automation from .Net) to scroll through a list of Excel
files and do something (which is immaterial to this question) with those
files.

That is working - until I get to a file which is password protected where
when I try to open the file it pops up the password box and stops my code.
Is there a property of the workbook that I can grab that says "this is
protected" so that I can skip that file?


--

Dave Peterson
  #3   Report Post  
Rob Oldfield
 
Posts: n/a
Default

Perfect. I just feed the line of code I'm using to open a file a password
and it just comes up with an error - which I can catch and cope with. I
guess it would be the same for automation from anything.

Many thanks.


"Dave Peterson" wrote in message
...
First, I don't know anything about .Net.

But excel is pretty interesting.

If you try to open a non-protected workbook via code, it won't care if you

try
with a bad password. If the workbook is protected, the workbook won't

open --
but you won't get prompted.

For instance:

Option Explicit
Sub testme()
Dim wkbk As Workbook
Dim myList As Variant
Dim bCtr As Long
Dim myPath As String

myPath = "C:\my documents\excel\"
myList = Array("book2.xls", "book1.xls", "book3.xls")

For bCtr = LBound(myList) To UBound(myList)
Set wkbk = Nothing
On Error Resume Next
Set wkbk = Workbooks.Open(Filename:=myPath & myList(bCtr), _
ReadOnly:=True, Password:="xxx")
On Error GoTo 0

If wkbk Is Nothing Then
MsgBox "either missing or wrong password: " & myPath &

myList(bCtr)
Else
wkbk.Close savechanges:=False
End If
Next bCtr

End Sub

I could even use: password:=""
in that .open statement if I were afraid of guessing the correct password.


Rob Oldfield wrote:

I'm attempting (via automation from .Net) to scroll through a list of

Excel
files and do something (which is immaterial to this question) with those
files.

That is working - until I get to a file which is password protected

where
when I try to open the file it pops up the password box and stops my

code.
Is there a property of the workbook that I can grab that says "this is
protected" so that I can skip that file?


--

Dave Peterson



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
Recently Used File List - 2002 Contains 'Temp' Files Keith972002 Excel Discussion (Misc queries) 0 July 26th 05 01:46 PM
how to automate opening a password protected excel file? e.g. a .xls that has a password set in the security tab. Daniel Excel Worksheet Functions 0 June 23rd 05 11:56 PM
I CANNOT SAVE MY FILES THE DIALOGUE BOX SAYS THEY ARE PROTECTED A. SB Excel Discussion (Misc queries) 1 February 3rd 05 09:27 PM
Password protected files Forgotten password problem! Excel Discussion (Misc queries) 4 December 20th 04 12:28 PM
importing multiple text files URGENT!!! HELP tasha Excel Worksheet Functions 0 December 19th 04 04:26 PM


All times are GMT +1. The time now is 08:57 AM.

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"