Solved

VBA - skip files that are password protected

Posted on 2011-09-08
8
357 Views
Last Modified: 2012-05-12
Hello,

I have a macro that cycles thru a group of Excel files inside a folder and makes updates.  A small number of the files are password protected.  I don't need to update the password protected files.  One issue I have right now is I'm not able to get rid of the pop up that requests the password.  When a file is password protected, I'd like to be able to identify it's password protected (or that I wasn't able to open it) and then move on.  How would you suggest I go about accomplishing this?  I'm just looking for the code right around the workbook open statement.  

I'm currently using Excel 2003.

Thanks for your help,

Steve

0
Comment
Question by:ClayCanvas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
ID: 36503582
Function hasPW(ByVal path As String) As Boolean
On Error Resume Next
Workbooks.Open path, Password:=xxx
If Err.Number > 0 Then
    hasPW = True
Else
    hasPW = False

End If


End Function
0
 

Author Comment

by:ClayCanvas
ID: 36503726
Thanks for your feedback.  I think that would work well but I seem to still have one issue remaining.  I don't seem to be able to suppress the pop up request for password.  It's a shared workbook that's password protected if someone wants to make changes or they're given the option to click a button to open "read only".

Thanks,

Steve
0
 
LVL 16

Expert Comment

by:carsRST
ID: 36503761
When I run that code, I do not get a password box.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:carsRST
ID: 36503772
see sheet.
pwtest.xls
0
 
LVL 16

Expert Comment

by:carsRST
ID: 36503785
Wait...mine is not shared.  Let me try that.

sorry...
0
 
LVL 16

Expert Comment

by:carsRST
ID: 36503801
I get same result.  
0
 

Author Comment

by:ClayCanvas
ID: 36504435
you mentioned you get the same result in your last post.  Does that mean you're also getting a pop up requesting the password or does that mean getting the same result you initially received when you did not get a pop up?  

For some reason when I use the function you provided I'm still getting a pop up that's providing me with two options... enter a password or click the "Read Only" button.

Thanks,

Steve
0
 

Author Closing Comment

by:ClayCanvas
ID: 36510483
Thanks for the idea regarding the function to open the workbooks and determine whether or not a workbook was open.  For some reason I'm not able to stop the password pop up from showing up.  I'll post a new question and see if someone has an idea as to how I can keep the password input box from showing up.

Steve
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question