Excel thinking cells are locked when they aren't - excel

I have quite a complicated workbook which i have very heavily locked down so it cant lose its structural integrity when being used by the user. It works like a dream in Excel 2003, 2007 and 2010 however when i use it in 2013 if i try and type in to an unprotected cell excel thinks that its protected, i can then unprotected the sheet manually and it still wont let me type in to the cell im then mysteriously allowed to unprotected the worksheet AGAIN and then it allows me to enter in to the cell and also get in to the cell formatting to demonstrate that the cell is definitely not locked. Its then made even more complicated when i then navigate to another protected sheet and i then find it unprotected.....
I have messed about with the sheet more and more and the problem appears to be when my macro moves me from one sheet to the next it believes its still on the previous sheet.
For example on the front sheet i have cell K16 as named cell called "ChangePW"
I then run my macro to select another sheet (shown below)
Application.ScreenUpdating = False
Sheets("Income&Expenditure").Select
Worksheets("Income&Expenditure").Unprotect Password:="*****"
Range("B3").Value = "OSC"
Worksheets("Income&Expenditure").Protect Password:="*****"
Range("B2").Select
Application.ScreenUpdating = True
I then proceed to enter some data in to the the Income&Expenditure tab but i get a warning that the sheet is protected even though i have selected an unprotected cell. I then click on cell K16 on the Income&Expenditure sheet and it still thinks its called "ChangePW". As a result of this its applying the protection layout of the front sheet on the Income&Expenditure sheet. Even when i click on the Income&Expenditure tab at the bottom and click "Show Code" its showing me the code for the Front Sheet!!
All of the vba works perfectly in 2007 and 2010 so im absolutely stumped at the moment.
I have been navigating forums for the last 2 weeks trying to find an explanation with no successes, has anyone else experienced anything like this or know of a cause? i reiterate that it works perfectly in all other versions of Excel....
Thanks

I've been solving the same behaviour. The bug is in opening files from a modal UserForm. The solution is to open a UserForm as modeless.
Either calling:
MyForm.Show False
or adding Layout event procedure to a UserForm:
Private Sub UserForm_Layout()
Static fSetModal As Boolean
If fSetModal = False Then
fSetModal = True
Me.Hide
Me.Show 1
End If
End Sub
Read: http://msdn.microsoft.com/en-us/library/office/dn251093.aspx

Related

Edit Objects are not working in protected workbook

I have an excel document that is protected. I have a macro running to allow for expanding and collapsing rows in 1 of the sheets that looks like this:
Private Sub Workbook_Open()
With Worksheets("Part 1")
.EnableOutlining = True
.Protect UserInterfaceOnly:=True
End With
End Sub
This was working great, however now I would like to allow for "drawing" to have the text in that spreadsheet to be highlighted. I have gone into the "protect sheet" function to allow for "edit objects", I protect the sheet, save and exit. When I reopen the document it does not allow for me to use the "draw" function. And when I unprotect the sheet, the "edit objects" is selected, but the draw buttons do not work until I "unprotect" and then "protect" it again.
This is only happening in the sheet that has the macro running, thinking this might be a macro code. Any ideas?
As mentioned above, I have tried to unlock and relock the spreadsheet, however the edit objects function does not save upon next reopen. I am hoping to get assistance on the macro as I feel it is creating the error.

Excel graphical glitches when moving between sheets with private subs?

I encountered an odd graphical glitch when running private subs on a sheet then using a macro to jump to another sheet with a private sub on it. Basically excel is getting slowed down (the drop down menu's in the ribbons get messed up as well).
IE:
Sheet 1 has
Private Sub Worksheet_Deactivate()
Sheets("Sheet1").Visible = False
End Sub
Sheet 2 has the above code as well except Sheet2 would be the one made hidden when deactivating the worksheet.
With a button placed on sheet1 which trigger the following macro
Sub Sheet1_Button1_Click()
Sheets("Sheet2").Visible = True
Sheets("Sheet2").Select
End Sub
For testing purposes I was just using another macro assigned button on sheet2 that jumped back to sheet one and found that caused the issue. Does anyone know what's going on here and how to prevent it? Maybe this is more of a Microsoft issue?
In my original workbook I had a private sub on a "Cost Estimations" sheet that would run some some code to un-hide used lines and re-hide unused lines in a table that was referencing another sheet. Then I had a macro assigned button on that same sheet that would open a normally hidden sheet with some more info on it. The "hidden" sheet had a private sub on it that automatically hide it when the user clicks off of the sheet just like the "Sheet1" in my example. Additionally in the original workbook it was causing all the information from "cost estimations" to display on the "hidden" sheet, but only if calculations were set to automatic. I was however unable to replicate that in my test worksheet.

Remove error indicating unlocked cells are protected with VBA

I have a template sheet that is copied through VBA into a new sheet.
The new sheet is added by clicking on a button that makes a userform pop up, and the information in the userform is transferred to the new sheet.
This new sheet contains locked headline cells as well as unlocked empty cells for the user to put information into. The sheet is protected but allows users to select locked and unlocked cells.
Everything worked for some months until the other day. When a new sheet is created and the user tries to fill in the unlocked cells, Excel responds as if they were locked!
The following information pops up:
"The cell or chart you're trying to change is on a protected sheet. To make changes, click Unprotect Sheet in the Review tab (you might need a password)."
This error disappears after the user does any of the following
1) double click in any empty cell (instead of just selecting it) and put in information this way and then click enter, then all cells behave normally.
2) activate any other worksheet and then return to this sheet
3) choose Format>Unprotect Sheet (this does not unprotect the sheet but it removes the error. If the user wants to unprotect the sheet then they have to click Format>Unprotect Sheet twice, i.e. first to remove this weird error and then to unprotect it).
I am trying, with VBA, to remove this error by doing any of 1, 2 or 3 above.
Any ideas how to solve this?
An additional problem is it is not possible to scroll with the mouse in the sheet while having the problem.
I tried the following code:
ActiveSheet.EnableOutlining = True
ActiveSheet.Protect Contents:=True, userInterfaceOnly:=True
After some googling I managed to solve this by doing the following:
Create a Module in VBA and add the following code:
Public Sub RefreshActiveCellSelection()
ActiveCell.Select
End Sub
Whenever you perform a Workbook.Activate or Worksheet.Activate, immediately call
Application.OnTime Now, "RefreshActiveCellSelection"
Another solution was to uninstall KB3085502
I found the answer here: http://answers.microsoft.com/en-us/office/forum/office_2013_release-office_install/microsoft-update-excel-2013-kb3085502-32-bit/0cc7d498-92cb-4478-9554-77cff286c847

Unprotect and change style with vba

Sheet1.Unprotect
Sheet1.Cells(13, "E").Locked = False
Sheet1.Range("E13").Style.Name = "Normal"
Sheet1.Protect
Produces:
The cell or chart you're trying to change is on a protected sheet.
To make changes, click on Unprotect Sheet in the Review tab (...)
On the other hand:
Sheet1.Unprotect
Sheet1.Cells(13, "E").Locked = False
Sheet1.Protect
runs instead properly.
Had the same problem with the, 'The cell or chart you're trying to change is on a protected sheet. To make changes, click on Unprotect Sheet in the Review tab (...)', error message coming up.
Realized I had protection on an another worksheet in the workbook which had to be turned off before I could modify the Normal style. Makes sense if you think about it!
Once all protection was turned off I can modify the Normal Style.
Rogerc

Protected Sheet Warning On Any Edit

Hoping to get some help with Excel 2010.
I have three visible sheets. On Workbook Open, vba password protects each of the three sheets.
Now, whenever I make a change to any unlocked cell in any sheet, I get 4 protected sheet warning pop-ups. The one that says that the cells are locked and you have to unprotect to edit? That's all well and good except that I am not editing locked cells. I am editing unlocked cells in other sheets!
Has anyone had this experience? I have played around and two of them can be attributed to each of two sheets. That is to say, when I only protect the first sheet, I get no pop-ups, when I protect only the second, I get 2 and when I protect only the third, I get 2.
Taking out formulas hasn't made a difference.
Here is the code for the locking:
For Each wSheet In Worksheets
wSheet.Unprotect Password:="JMP_DST_Lock"
If wSheet.Visible = True Then
wSheet.Protect Password:="JMP_DST_Lock", UserInterFaceOnly:=True
wSheet.EnableOutlining = True
End If
Next wSheet
ThisWorkbook.Protect Password:="JMP_DST_Lock"
Thank you very much for any help.
EDIT:
Turns out the comboboxes are the reason for the error. If the linked cells are locked, anytime the sheet calculates (any change when on automatic calculation) causes the warnings. Now, I have code that unprotects the sheets on each combobox GotFocus, but aside from that, these are cropping up.
Is there a middle ground? A way to keep the linked cells locked without these warnings popping up? A way to make sure the comboboxes are hitting the linked cells except on selection?
Thank you!
Your logic seems wrong. You're unprotecting the sheet, then protecting visible sheets, and then protecting the entire workbook (in the last code line).
Try something like this instead (untested):
For Each wSheet In Worksheets
If wSheet.Visible = True Then
wSheet.Protect Password:="JMP_DST_Lock", UserInterFaceOnly:=True
wSheet.EnableOutlining = True
End If
Next wSheet
If the workbook is saved with the sheets in protected state, change it to something like this instead:
For Each wSheet In Worksheets
If wSheet.Visible = False Then
wSheet.UnProtect Password:="JMP_DST_Lock"
End If
Next wSheet

Resources