ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Skip past Password Protected Excel file (https://www.excelbanter.com/excel-programming/399078-skip-past-password-protected-excel-file.html)

koops2121 via OfficeKB.com

Skip past Password Protected Excel file
 
I have a routine that is going through Excel files and making a change to
every file in a specified folder.
This works great until I hit a file that's password protected. Since I don't
know the password I want to log then skip it.
Is there a way to open a workbook, not know the password, realize it has a
password and close it down and move on to the next file in the folder?

Thanks,

--
Message posted via http://www.officekb.com


JW[_2_]

Skip past Password Protected Excel file
 
I'm assuming that you are setting a variable to hold the workbook
currently being processed. If so, use something like this:
If wb.HasPassowrd Then
'whatever you want to happen
End If

Would need to see your code to recommend the proper spot to place
this.

koops2121 via OfficeKB.com wrote:
I have a routine that is going through Excel files and making a change to
every file in a specified folder.
This works great until I hit a file that's password protected. Since I don't
know the password I want to log then skip it.
Is there a way to open a workbook, not know the password, realize it has a
password and close it down and move on to the next file in the folder?

Thanks,

--
Message posted via http://www.officekb.com



koops2121 via OfficeKB.com

Skip past Password Protected Excel file
 
Sorta yes.

I do this:

Set xApp = CreateObject("Excel.Application")
Set xBook = xApp.Workbooks.Open(objFile.Path)

If I then do xBook.HasPassword = True, it's too late and I'm already stuck at
the prompt asking for a password from the Open command. Maybe I'm doing this
wrong.

Thanks,

--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200710/1


Gary Keramidas

Skip past Password Protected Excel file
 
does the workbook require a password to open it, or just to modify a worksheet?

--


Gary


"koops2121 via OfficeKB.com" <u37561@uwe wrote in message
news:797d9d9277067@uwe...
I have a routine that is going through Excel files and making a change to
every file in a specified folder.
This works great until I hit a file that's password protected. Since I don't
know the password I want to log then skip it.
Is there a way to open a workbook, not know the password, realize it has a
password and close it down and move on to the next file in the folder?

Thanks,

--
Message posted via http://www.officekb.com




koops2121 via OfficeKB.com

Skip past Password Protected Excel file
 
It requires a password to open it.
So everything hangs until you enter a password.

--
Message posted via http://www.officekb.com


koops2121 via OfficeKB.com

Skip past Password Protected Excel file
 
It requires a password to open it.
So everything hangs until you enter a password.

--
Message posted via http://www.officekb.com


Dave Peterson

Skip past Password Protected Excel file
 


Dim TestWkbk as workbook
inside your looping code...
set testwkbk = nothing
on error resume next
set testwkbk = workbooks.open(filename:=theloopvaluehere,password :="")
on error goto 0
if testwkbk is nothing then
'it wasn't opened, skip it
else
'opened ok
'do the real work here.
end if
end of loop


"koops2121 via OfficeKB.com" wrote:

I have a routine that is going through Excel files and making a change to
every file in a specified folder.
This works great until I hit a file that's password protected. Since I don't
know the password I want to log then skip it.
Is there a way to open a workbook, not know the password, realize it has a
password and close it down and move on to the next file in the folder?

Thanks,

--
Message posted via http://www.officekb.com


--

Dave Peterson

[email protected]

Skip past Password Protected Excel file
 
I was actually having the same problem except I was using the
Office.Interop library from a C# class and
every time I tried to open a workbook with a password an actual Excel
prompt would appear, which was no good.
The key insight for me was that entering "" as a password parameter
would cause no problems opening non password
protected files.

In my case I had to do something like this:

try{
myExcelApp.WorkBooks.Open(filename,...,"",...)
}
catch (System.runtime.InteropServices.COMException e)
{
// workbook is password-protected, gracefully exit
}

// continue with non-password-protected workbook

Thanks Dave for your elucidating post.

On Oct 10, 3:05 pm, Dave Peterson wrote:
Dim TestWkbk as workbook
inside your looping code...
set testwkbk = nothing
on error resume next
set testwkbk = workbooks.open(filename:=theloopvaluehere,password :="")
on error goto 0
if testwkbk is nothing then
'it wasn't opened, skip it
else
'opened ok
'do the real work here.
end if
end of loop

"koops2121 via OfficeKB.com" wrote:

I have a routine that is going through Excel files and making a change to
every file in a specified folder.
This works great until I hit a file that's password protected. Since I don't
know the password I want to log then skip it.
Is there a way to open a workbook, not know the password, realize it has a
password and close it down and move on to the next file in the folder?


Thanks,


--
Message posted viahttp://www.officekb.com


--

Dave Peterson





All times are GMT +1. The time now is 01:15 PM.

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