ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   password protected (https://www.excelbanter.com/excel-programming/383251-password-protected.html)

greg

password protected
 
Hello,
I need to write a program to open and update a bunch of excel documents.
problem is, that some are password protected.
and if i hit them, then the user password dialog opens.
is there a way to tell if a document is password protected? an open
command?
so i know to skip that document?

thanks



Tom Ogilvy

password protected
 
Dave Peterson suggested this to as similar question:

Dim wb as Workbook
For i = 1 To .FoundFiles.Count
Set wb = Nothing
On Error Resume Next
Set wb = Workbooks.Open(Filename:=.FoundFiles(i), _
Password:="", writerespassword:="")
On Error GoTo 0
If wb Is Nothing Then
'don't do anything, it wasn't opened!
MsgBox "not opened"
Else
'do your real work here
MsgBox "it's open"
End If
Next i

This was using the FileSearch Object, but you can use the approach with any
list of files.

--
Regards,
Tom Ogilvy



"greg" wrote:

Hello,
I need to write a program to open and update a bunch of excel documents.
problem is, that some are password protected.
and if i hit them, then the user password dialog opens.
is there a way to tell if a document is password protected? an open
command?
so i know to skip that document?

thanks




greg

password protected
 
awesome!
I will give it a try




"Tom Ogilvy" wrote in message
...
Dave Peterson suggested this to as similar question:

Dim wb as Workbook
For i = 1 To .FoundFiles.Count
Set wb = Nothing
On Error Resume Next
Set wb = Workbooks.Open(Filename:=.FoundFiles(i), _
Password:="", writerespassword:="")
On Error GoTo 0
If wb Is Nothing Then
'don't do anything, it wasn't opened!
MsgBox "not opened"
Else
'do your real work here
MsgBox "it's open"
End If
Next i

This was using the FileSearch Object, but you can use the approach with

any
list of files.

--
Regards,
Tom Ogilvy



"greg" wrote:

Hello,
I need to write a program to open and update a bunch of excel documents.
problem is, that some are password protected.
and if i hit them, then the user password dialog opens.
is there a way to tell if a document is password protected? an open
command?
so i know to skip that document?

thanks







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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com