Solved

VBA - skip files that are password protected

Posted on 2011-09-08
8
327 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
  • 5
  • 3
8 Comments
 
LVL 16

Accepted Solution

by:
carsRST earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
When I run that code, I do not get a password box.
0
 
LVL 16

Expert Comment

by:carsRST
Comment Utility
see sheet.
pwtest.xls
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 16

Expert Comment

by:carsRST
Comment Utility
Wait...mine is not shared.  Let me try that.

sorry...
0
 
LVL 16

Expert Comment

by:carsRST
Comment Utility
I get same result.  
0
 

Author Comment

by:ClayCanvas
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
Drop Down List with Unique/Distinct Values (Part II - ComboBox or ListBox and Data Validation List Bonus!) David Miller (dlmille) Intro This article focuses on delivering unique, sorted lists to list objects (e.g., ComboBox, ListBox) and Dat…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.

728 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now