PDA

View Full Version : Solved: VBA Print Code and Protected Sheet Problem



Usethaschwar
08-15-2012, 11:52 AM
I have a form which I have created in excel for many people on different computers to fill out. I wrote a VBA code so that columns with costs are automatically blanked out when anyone wants to print out the form. I also have protected the document so that only the cells that need to be filled in can be edited. When the sheet is unprotected, the VBA printing code works fine, but when the sheet is protected, an error with the code pops up. Some of the cost columns are locked, and others are not. I will attach the entire document for viewing. When I tried to debug the code, the line: Sheet2.Range("O34:O50").Font.ColorIndex = 2 seemed to have an issue and I'm not sure why. Any suggestions?

Kenneth Hobs
08-15-2012, 07:08 PM
Was it error 1004? If so, you need to unprotect the sheet or use the UserInterfaceOnly=True option in the sheet's Protect method. I usually set that in the workbook's Open event so that code can modify cells.

Sheet2.Protect "ken", UserInterfaceOnly:=True
Sheet2.Range("O34:O50").Font.ColorIndex = 2