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
Solved

Excel macro - Save & PW Protect workbooks using range w/file path names&pws

Posted on 2013-11-05
3
352 Views
Last Modified: 2013-11-06
I have the need to make changes to 64 excel 2010 workbooks located in various folders in a directory. These workbooks and their worksheets are password protected. The sheets are all protected with the same pw, the workbook protection passwords change. I store the full path/filename in column "A" of a workbook where I start the macro. It's sheet is called 'Wbklist'.  I store the workbook password in Column "B". I've pieced together a routine that I'd like to use to open each sheet and make the same correction to each sheet or poll the data within. The macro loops through each sheet in column A and unprotects the workbook and sheets. After the changes or polling is done, I cant seem to lock the workbooks back down again. The worksheets are being password protected just fine, the workbook is not. Ive tried a million little things and I dont know what Im doing wrong. When I open an individual workbook after its run, the workbook is not passwork protected.

Thanks in advance for your assistance!
PW-Protect-Quest.txt
0
Comment
Question by:socallilly
  • 2
3 Comments
 
LVL 12

Expert Comment

by:Harry Lee
ID: 39625847
socallilly,

I think you have some error on your macro.

1) in your
            Set WBSsource = Workbooks.Open(FileNames(i, 1), _
                                           ReadOnly:=False, _
                                           Password:="")

Open in new window

You already have the file opened. and you don't need to open it again in
                With WBSsource
                    '---Unprotect WB and sheets and unhide all----
                    Workbooks.Open Filename:=FileNames

Open in new window


I have modified you code a little so that I don't have so many sheets per file, and the WB protect works just fine.

Which version of Excel are you using?


Have you tried change

WBSsource.Protect FilePW, Structure:=True, Windows:=False

to Activeworkbook.Protect FilePW, Structure:=True, Windows:=False
0
 
LVL 12

Accepted Solution

by:
Harry Lee earned 500 total points
ID: 39625872
Found your problem.

In the line

WBSsource.Protect FilePW, Structure:=True, Windows:=False

You have to do

WBSsource.Protect FilePW(i, 1), Structure:=True, Windows:=False

To call up the array for each password.
0
 

Author Closing Comment

by:socallilly
ID: 39628334
THANKS SO MUCH HARRY!!!!! I LOVE YOU!!!!!!
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction This Article briefly covers methods of calculating the NPV and IRR variants in Excel as well as the limitations in calculating and interpreting IRR results. Paraphrasing Richard Shockley, author of my favourite finance reference tex…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

839 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