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.
Related
I have a sheet that has some cells that have a list type data validation with "Show error alert..." unchecked so that you can still manually type an option that might not be in the list. this works when the sheet is not protected, but when it is, and the cell is unlocked, it no longer allows manually typing anything while the normal selection from the list works fine. I use the following code to protect the sheet whenever it is opened.
Private Sub WorkBook_Activate()
ActiveSheet.Protect Password:="Password", UserInterfaceOnly:=True
ActiveSheet.EnableSelection = xlUnlockedCells
End Sub
When I manually protect the sheet (unprotect it then protect it myself in the review tab) I can select "Edit Objects" and that does exactly what I want. The only results that come up when trying to figure out how to do that with VBA use DrawingObjects:=False when protecting it.
I have already tried using
ActiveSheet.Protect Password:="Password", UserInterfaceOnly:=True, DrawingObjects:=False
but this for whatever reason does not protect the sheet at all. Is this the wrong approach? What's going on?
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 a worksheet that is populated from userform information, and from a few other spreadsheets in the same file. I have used the following code:
Application.Dialogs(xlDialogPrint).Show
I ensure the sheet is activated before printing, and I have gotten the function working correctly.
This sheet and others in the workbook must be protected to prevent changes by the user outside of a userform. When I protect the sheet and add appropriate code to unlock that sheet a few things happen:
1. The userform is filled as designed.
2. The print dialog box shows up as designed.
3. When the print button is pressed on the dialog box, it will not print. Not a printer issue: It will not print to PDF either.
How can I get it to actually print the worksheet like I need?
You can unprotect the sheet by using
ActiveSheet.Unprotect
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.unprotect
Then protect it after working with it using
ActiveSheet.Protect
https://learn.microsoft.com/en-us/office/vba/api/excel.worksheet.protect
banal code below must do the work without need to unprotect and protect
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Preview:=True, Collate:=True
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.