Solved

VBA - skip files that are password protected

Posted on 2011-09-08
8
371 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

729 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