I'm trying to disable (or hide) specific right click options on the Excel sheet/tab menu. I don't want to disable the entire menu per this thread.
I've tried in both Excel 2010 & 2016, same result. The code runs fine but the options in the sheet right click menu are still enabled. I've tried using the control's name and ID to no avail.
Private Sub Worksheet_Activate()
Application.CommandBars("cell").Controls("cut").Enabled = False 'Works
With Application.CommandBars("Ply")
.Controls("Insert...").Enabled = False
.Controls("&Select All Sheets").Enabled = False
.Controls("Select All Sheets").Enabled = False
.FindControl(ID:=946).Enabled = False '&Select All Sheets ID:946
'.Enabled = False 'Works but don't want entire menu disabled
End With
End Sub
After code, options are still enabled:
Thanks in advance.
Related
So I have looked at various questions similar to this but they don't seem to work or are unanswered:
Run macro when slicer change
how to run a macro while clicking on a value in slicer in excel vba
My Question:
When i click one of the options in the slicer i want it to automatically run one of the macros but it doesn't work, when i run it manually it works, but clicking on the slicer's option doesn't
Sub updateFoodSlicer()
With ActiveWorkbook.SlicerCaches("Slicker_TABLE_StackChart")
.SlicerItems("food").Selected = True
.SlicerItems("fruit").Selected = False
.SlicerItems("drink").Selected = False
End With
With ActiveSheet.PivotTables(Foods_StackChart").PivotFields("FOODS")
.PivotItems(">0").Visible = False
.PivotItems(">2").Visible = False
.PivotItems(">4").Visible = False
.PivotItems(">6").Visible = True
.PivotItems(">8").Visible = True
End With
End Sub
Thats my macro, when i click run it works, but i want it so that when i click the option "food" from the slicer i want it to make columns >6, and >8 visible only
By checking out those above stackoverflow question I realized you need an event so I added that, but still it doesn't work:
Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
If ActiveWorkbook.SlicerCaches("Slicker_TABLE_StackChart").SlicerItems("food").Selected = True Then
Call updateFoodSlicer()
End If
End Sub
----------------------------
Sub updateFoodSlicer()
With ActiveWorkbook.SlicerCaches("Slicker_TABLE_StackChart")
.SlicerItems("food").Selected = True
.SlicerItems("fruit").Selected = False
.SlicerItems("drink").Selected = False
End With
With ActiveSheet.PivotTables(Foods_StackChart").PivotFields("FOODS")
.PivotItems(">0").Visible = False
.PivotItems(">2").Visible = False
.PivotItems(">4").Visible = False
.PivotItems(">6").Visible = True
.PivotItems(">8").Visible = True
End With
End Sub
EDIT:
Follow up, so I added into the Sheets tab so the macro would run, but now I get the error: method visible of object pivotitem failed
I have tried various solution from online, yet none seem to work
I am trying to unlock a combobox when a option button is enabled. I am using the following code in a module but when I run the code and select the option the combo box remains locked
If Custom = True Then
FromMonth.Locked = False
FromYear.Locked = False
ToMonth.Locked = False
ToYear.Locked = False
End If
I am hoping to find a way to simultaneously click the option button in the userform and have it unlock the combo boxes next to them
You can use the option button change event, and make sure to add the code into userform code module and not the normal module
Your code can be something like this
Private Sub Custom_Change()
FromMonth.Locked = Not Custom.Value
FromYear.Locked = Not Custom.Value
ToMonth.Locked = Not Custom.Value
ToYear.Locked = Not Custom.Value
End Sub
I have a userform with a multitab containing 8 tabs. I require a user to use checkboxes on tab 6. I'm try to disable the user from selecting the next tab (tab 7) if Checkbox 1 and Checkbox 2 are left unchecked. They should only be able to access the next tab if they select one of the two checkboxes.
Private Sub MultiPage1_Change()
If Failed1.Value = False Or Passed1.Value = False Then
Me.MultiPage1.Pages(7).Enabled = False
Exit Sub
ElseIf Failed1.Value = True Or Passed1.Value = True Then
Me.MultiPage1.Pages(7).Enabled = True
End If
End Sub
I can't quite get the code to work the way I want it to. Any help would be greatly appreciated.
FYI - I'm a VBA n00b.
Me.MultiPageName.Pages(index).enabled = false
Me = the form active where multipage is present
MulitipageName = named multipage
Index = place of the page to enable copied from:http://www.excelforum.com/excel-programming-vba-macros/534056-is-it-possible-to-disable-a-tab-page-on-a-multipage-userform.html
For my form I need to hide or disable a textbox with a on-click delete macro attached to it when the sheet is protected. I'm talking about excel's build-in protection system. I've looked at several tutorials but I can't seem to get it to work properly.
I tried multiple things including this:
If ActiveSheet.ProtectContents = True Then
TextBox1.Visible = False
Else
TextBox1.Visible = True
End If
Any idea how to do this?
Change
If ActiveSheet.ProtectContents = True Then
TextBox1.Visible = False
Else
TextBox1.Visible = True
End If
To
If ActiveSheet.ProtectContents = True Then
ActiveSheet.TextBox1.Visible = False
Else
ActiveSheet.TextBox1.Visible = True
End If
You are not declaring where the textbox is. This will fix it
It is not clear whether the textbox is embedded in the worksheet or in a userform.
If in the worksheet is it a text box based on a shape? These are created from the INSERT tab on the Ribbon.
Or is this an ActiveX textbox? These are created from the DEVELOPER tab on the Ribbon.
If on the other hand, you are referring to a textbox on a userform then you can use the following code (assuming the userform code name is UserForm1):
UserForm1.Controls("NameOfYourTextBox").Visible = Not ActiveSheet.ProtectContents
I would like to hide the formula bar in a specific Excel file and only in this file. I know we can do it with VBA (Application.DisplayFormulaBar = False) but I am wondering if there is another solution like editing the CustomUI file.
Usually I edit the CustomUI file for hiding ribbon, adding custom tabs, ... It would be nice if we can hide the formula bar in this way.
Any suggestions?
Thanks.
Short answer is: No, you cannot.
Unfortunately, you cannot hide it by editing the CustomUI file. The formula bar has to be hidden using VBA. That being said, you can just run the hide operation on the Workbook_open event.
Private Sub Workbook_Open()
Application.DisplayFormulaBar = False
End Sub
You can turn it on/off depending on the active sheet like so:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
If Sh.Name = "Sheet1" Then
Application.DisplayFormulaBar = False
Else
Application.DisplayFormulaBar = True
End If
End Sub
I know it's a 2011 issue, but the solutions shown above don't seem to be the right ones for the problem in question.
If you modify using vba Aplication.whatelse this change applies to the entire excel app
To fix this instead of turning on/off when you open/close the document uses the sheet's activate/deactivate events
This way when your hidden document is turned on and when you turn off swatches.
This works perfect for me, to hide status bar and formula bar.
I leave you code to see how it works
Private Sub Workbook_Activate()
Application.DisplayStatusBar = False
Application.DisplayFormulaBar = False
End Sub
Private Sub Workbook_Deactivate()
Application.DisplayStatusBar = True
Application.DisplayFormulaBar = True
End Sub
You can accomplish this by using the workbook activate en deactivate events.
Just put Application.DisplayFormulaBar = False into the activate event and Application.DisplayFormulaBar = true in the deactivate event.
To avoid all opened Excel sheet formula bar hidden you can go for hiding the formula for a particular excel.
Sub test()
Sheet1.Unprotect "test"
Range("A1").FormulaHidden = True ' range which you want to hide formula.
'your code here
Sheet1.Protect "test"
End Sub