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
Related
I have used this method before but after six months I cannot.
I created data entry fields through which I move data from Sheet1 to Sheet2 using a button.
I do not want users to see Sheet2 so that they cannot change anything. I was using the formulas below.
Sheets("Data Sheet").Visible = True
Sheets("Data Sheet").Visible = False
After hiding the sheet I protect them with the password. The main advantage of code is that I can still post the data from Sheet1 to Sheet2 after hiding.
Upon research I found one more formula to hide the sheet but after hiding sheet2 posting via Sheet1 to Sheet2 (which is hidden) gives an error.
ThisWorkbook.Worksheets(Array("Data Sheet")).Visible = xlSheetHidden
How can I hide Sheet2 and continue posting the entries via Sheet1.
You can manipulate data on a hidden sheet, no need to unhide it.
Unless you are trying to select cells, but you shouldn't have to do that.
You do however need to unlock a sheet before editing it if the cells are protected. You can do this as part of the process.
Sheets("Data Sheet").Unprotect Password:="pass"
----
whatever code you have
----
Sheets("Data Sheet").Protect Password:="pass"
You do might want to have some error handling in there however, since if the code throws an error, the sheet will be left unlocked.
a) The statements Sheets("Data Sheet").Visible = False and ThisWorkbook.Worksheets(Array("Data Sheet")).Visible = xlSheetHidden do basically the same. However, you will need to understand why it is important to qualify the Sheets: ThisWorkbook.Worksheets will access the worksheets from the workbook where the code lives in, just writing Sheets (or Worksheets) will access the sheets of the ActiveWorkbook - and that may be a different workbook. The Array("Data Sheet")-part is unnecessary in your case (you can pass an array of sheet names to hide more than a sheet at once). Setting visibility to xlSheetHidden or to False is identical.
b) Hiding a sheet and protecting a sheet are two different, independent things. You can protect a sheet but not hide it, you can hide a sheet but let it unprotected.
c) The main idea of protecting a sheet is to allow user input only at specific cells. The user can change the content of the sheet, but only to cells which are not formatted as "Locked".
d) If you protect a sheet via Excel (no matter if hidden or not) and want to modify something via code, you will need to unprotect it (and protect it again after the code is done). However, when protecting the sheet via code, you can specify that you want to allow the code to make modifications by setting the UserInterfaceOnly-parameter:
Thisworkbook.Sheets("Data Sheet").Protect Password = "IWontTellYou", UserInterfaceOnly:=True
e) If you never want to show the sheet, set the visibility not to hidden, but to veryHidden. With that, the sheet cannot be made visible by the use from within Excel: It will not be listed under "Unhide..." - in that case there is not need to protect it.
Thisworkbook.Sheets("Data Sheet").Visible = xlSheetVeryHidden
(Note that in that case you can make the sheet visible again only via code, but a one-liner in the immediate window is sufficient)
You will have to write a code to first unprotect sheet2, then paste the data and protect sheet2 again.
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.
I have created a dynamic workbook where i put and pull data to more sheets containing data from other sources. I have a "Temp" sheet where code updates som data, this sheet is hidden until the macro is run, to put and pull data, i make it visible and when finished i hide it again. This works (almost) perfect.
The problem occurs when i hide it, then my last Sheet i selected automatically? My code is totally without any .select or .active (Still learning) because it is important that code always return to the sheet from where the code is run as this changes name everyday.
I can't seem to find anything that solves my issue, hope somebody can help:
I tried the following, as you can see in the following code:
Sheets("Temp").Cells.ClearContents
Sheets("Temp").Visible = False
'Cleans filters
ActiveSheet.ShowAllData
Application.Goto Range("A4")
Application.ScreenUpdating = True
I want to always stay in my activesheet (example: ("16") which is the actual date, there will be one sheet for everyday etc. ("17"), ("18") and so on.)
You can use With to immediately reactivate the sheet, like so:
With ActiveSheet
OtherSheet.Visible = xlSheetVisible
.Activate 'Immediately reactivate the ActiveSheet
End With
(You may want to toggle Application.ScreenUpdating so that you do not see so much as a flicker of the other sheet)
However, why do you need to show the sheet to copy data from it? If you are not using Select (which you say you are already sorted on), then you should be able to do most things with a Hidden sheet, such as HiddenSheet.Range("A1:B3").Copy
(A "Very Hidden" sheet, on the other hand, has a couple of restrictions - for example, you cannot delete a Very Hidden sheet.)
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
I have a spreadsheet with one sheet named "Sheet1". I have unhidden all other sheets and removed them. When I open the VBA editor, under "Microsoft Excel Objects" I have nearly 4000 Sheets listed, and I cannot remove them via right click.
It is my belief that this is causing the file's size to be way too large (~6 MB) when there is no data held in "Sheet1". I have tried using the "goto>special>objects" method, and no objects are found this way.
Any ideas on how to clear out all these empty objects?
I think I found a solution, at least it's working for me and I'm not very savvy with VBA. Add the Properties Window (under view), select each sheet, and change the Visible option to -1 - xlsheetvisible, it will make it appear in the excel and then you can delete the tab.
There are many ways to achieve what you want. The fastest way is right click on Sheet1 and click on "Move or Copy" ~~> "New Book" ~~> "OK"
Now you can save the new workbook and delete the old one :)
FOLLOWUP
Unfortunately this won't work - we have some pretty lengthy formulas in other sheets with this exact problem and Excel will only copy the first 255 characters of them. Additionally, the VBA code in the original sheet is not copied, involving additional steps to rebuild each spreadsheet affected with this problem.
In such a case try this code
Option Explicit
Sub Sample()
Dim ws As Worksheet
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each ws In ThisWorkbook.Sheets
If ws.Name <> "Sheet1" Then ws.Delete
Next
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub