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.
Related
I want to run the macro 'HighlightMisspelledCells' defined in the module node of Personal.xlsb on cell change of any workbook sheet.
I know that if I insert the following code on the sheet node in VBA Editor then this will call the macro defined in Personal.xlsb, but then for this, I have to insert this code every time for every new sheet, so is there any other way by which I simply add few lines in the PERSONAL.XLSB macro which runs on cell change of any opened sheet.
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Run "Personal.xlsb!HighlightMisspelledCells"
End Sub
Note : There is also another problem (not specific to the question) is, when I save the above code then get an error message box "The Following feature cannot be saved in macro-free workbook" but still code works if I click on 'Yes' to save. But when I opened the same workbook next time then this 'Sheet specific' VBA code disappears.
PERSONAL.XLSB
Sub HighlightMisspelledCells()
Dim cl As Range
For Each cl In ActiveSheet.UsedRange
If Not Application.CheckSpelling(word:=cl.Text) Then
cl.Interior.Color = vbRed
End If
Next cl
End Sub
Note : I am using MS Excel 2016 on Windows PC
I have already tried searching on the internet but have not been able to find a solution to my specific problem.
I want to have a button Show/hide all comments on the active Excel sheet only. I implemented and am fairly happy with this solution (using Application.DisplayCommentIndicator):
Simple VBA Show/Hide Excel Comments problems
The only issue is that this solution shows/hides comments on every sheet open in the application. I need it to only operate on the active sheet (IE. the one with the button) This is especially inconvenient because the other sheets (in other workbooks) don't have the Show/Hide button.
I have a semi-fix for your issue. Let's say if the user pressed your button to hide the comments, which is located in Sheet1, but then decides to switch to another worksheet, all comments would be activated again.
Problem: if the user switches back to Sheet1, the comments will be hidden and the user would have to press unhide regardless of their previous selection if they would like to see the comments:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet1" Then
Application.DisplayCommentIndicator = xlCommentIndicatorOnly
Else
Application.DisplayCommentIndicator = xlCommentAndIndicator
End If
End Sub
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
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 developed an Excel Application in which useres can enter custom categories. I let the user call up and hide this data entry worksheet with a button in the custom ribbon.
Now I've realized that the user can accidentally delete these worksheets. How do I disable the delete command for this worksheet while leaving all else open?
I've been searching the web but have come up empty on this.
This is for Excel 2007
Thanks
Protect them.
Tools > Protection > Protect Worksheet.
Add the password and choose what actions your users should do in the sheets.
You can do the same using VBA too. Check the following link
Updated with a code for sheet level protect
You may put the following code in the sheet that you need to manage any mischief ;)
Private Sub Worksheet_Activate()
ThisWorkbook.Protect Password:="Password", Structure:=True
End Sub
Private Sub Worksheet_Deactivate()
ThisWorkbook.Unprotect Password:="Password"
End Sub
But you see, when you have a book with 100 sheets and if you want 50 sheets to be protected.
Then you gotta either save all the sheet indices into a very hidden sheet. Usee that list in a module level VBA code to trigger the protect. Because not everytime you will have sheets in asceding order. If sheet indices in an order you can simply iterate them.
Let me know if you like to have workbook level code as well.