excel vba - unprotect sheet to format cells

C

chief

I have a workbook set up and i'm having a tough time with this
protection stuff. I have tried different .unprotect methods but it
doesn't work. I have a print button with coded conditions such as if
cell a1 = "this" then certain cells get the borders formatted to be
white, etc. then it prints one page, changes the format back and then
prints 2 pages like that and saves the page. Anyways, bottom line is
that there are format changes which are done before and after printing.
My code is set up so that as soon as the person goes into the main page,
it becomes protected in order to save formulas in certaing cells, then
when they click this print button the sheet SHOULD unprotect, allow for
these changes and printing to happen and then close. I don't care about
re-protecting the sheet after printing because the code is set up to
close the sheet as soon as it prints. Can anybody please help me, I'm
going nuts. If it makes it easier I can post the codes in a reply.
Thanks
 
D

Dave Peterson

I would think some code like this would work:

Option Explicit
Sub testme()

Dim wks As Worksheet

Set wks = Worksheets("sheet1")
With wks
.Unprotect Password:="hi"
'your formatting here
.PrintOut preview:=True 'just for testing
.Parent.Close savechanges:=False
End With
End Sub


But it's difficult to guess the problem you're having.
 
C

chief

Here is what happens. It comes up saying "Unable to set the Linestyl
property of the border class" ?


Why is this program being so testy?

The attachment file is too big to send, so if you are interested I ca
send it via email so that someone who wants to help can go on and se
exactly what the problem is. NOTE: To get in, click one of the thre
buttons, then type "Maggie" for an unprotected sheet, and "Carl" t
test out the program with the cells protected. As I said before, th
problem is that the sheet won't unprotect itself in order to mak
format changes and then allow itself to print.

Thanks

P.S. The attemptee will have to change the Userform1 code afte
Activeworkbook.save so that it will run properly on their own computer
 
D

Dave Peterson

If you do it manually, does it work?

If you paste your code and a bit of data, maybe someone who doesn't want to open
your workbook can help.

Most people don't want attachments posted to the newsgroups--so thanks for not
doing that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top