Context Menu - Hide all buttons and add my buttons only - vba

I am looking for a way to hide all the buttons from the Excel context menu and just leave my buttons I created.
How can I do that?

I found a way to do this, When i got same problem..
If you want to remove any item
Sub RemoveItems()
Application.CommandBars("Cell").Controls("Insert...").Delete
Application.CommandBars("Cell").Controls("Cut").Delete
Application.CommandBars("Cell").Controls("Copy").Delete
End Sub
Or if you want to delete all items then
Sub DeleteAll()
Set CtrlMenu = Application.CommandBars("Cell")
For Each Item In CtrlMenu.Controls
Item.Delete
Next
End Sub
If you want to restore again
Sub ResetMenu()
Application.CommandBars("Cell").Reset
End Sub

Related

How to make a button greyed out FOREVER in MS Access

What I am trying to accomplish is this:
Make a button for End Time which greys out once it is clicked. When moving to a new or the next record the button appears not greyed out, but will grey out once clicked. However, when I move to the new record, the button previously clicked in the previous records appear once again. Below is my code for the on-click function of the button:
Private Sub Command28_Click()
txtEndTime = Time()
Command28.Enabled = False
End Sub
I have also written this code for the Form_Current function:
Private Sub Form_Current()
If Me.NewRecord Then
Me.Command28.Enabled = True
End If
End Sub
Any help would be greatly appreciated.
Try with:
Private Sub Form_Current()
Me!Command28.Enabled = Me.NewRecord
End Sub
And do rename it to something meaningful.

Controlling multiple buttons through a single button

I have created 10 different buttons and each button has a unique SUB() assigned to it.
I now want to execute all the 10 buttons at a single click through a master button. Is that possible ? Can someone guide me?
assuming your "master" button is named after "MasterBtn" you just add its following click event handler:
Private Sub MasterBtn_Click()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeName(ctrl) = "CommandButton" Then If ctrl.name <> "MasterBtn" Then ctrl.Value = True
Next
End Sub
this approach is:
"robust"
in that you don't have to bother about remembering to "list" all other macro names
"maintainable"
in that you don't have to change this sub no matter how many buttons you may add or remove in your further coding development
You can call your macros
Sub AllMAcros()
macro1
Macro2
Macro3
End Sub
Whatever the macro names are
Call all the sub executions from the 'master button'. You can call another sub by using the CALL statement.
Example:
Sub MasterButton()
Call Button1
Call Button2
End Sub
You can also "click" on the buttons by changing its values to "True":
Sub clicking()
yourButtonName1.Value = True ' <- click
yourButtonName2.Value = True ' <- click
yourButtonName3.Value = True ' <- click
End Sub

vba userform checking the GroupName instead of an individual button

I'm using a VBA Userform. The MassPrompt userform has a set of six GroupNames and some text boxes. Each GroupName contains two or more radio buttons.
I'd like the following code to be triggered anytime any element within the GroupName "GROnly" changes. If the user made an inappropriate button choice in "GROnly" based on the choice in another group, I'd like to display a warning message and present the MassPrompt userform again.
Right now, I've assigned the code to the one button "GROnly_yes". It works, but only when that one button is clicked. How do I position this within the UserForm code to trigger anytime a button with the GroupName "GROnly" is clicked? Thanks for looking at this.
Private Sub GROnly_yes_Click()
'Prompt if the GROnly is true and it's inappropriate for the GSetting choice
If GROnly_yes = True And GSetting_renewal = True _
Then
GROnly_yes = False
GROnly_no = True
MsgBox ("The GROnly can't be chosen with a Renewal." & vbNewLine & _
"The GROnly button has been changed to 'NO'.")
UserForm_Initialize
End If
'Other IF statements here.
End Sub
If I understood well, GRonly is the GroupBox that contains (let's say) the radio_button_1 and radio_button_2.
The reason why the code doesn't trigger is that when he/she changes the value of one radio-button is not clicking on the GroupBox, but rather changing the value of that single radio-button.
You will have to add the code to the _Change event of the radio button objects. This is an example:
Sub myFunctionalCode()
'your code here
End Sub
Private Sub radio_button_1_Change()
myFunctionalCode
End Sub
Private Sub radio_button_2_Change()
myFunctionalCode
End Sub
Thanks for the reply. That would work.
In the meantime, I came up with another alternative as well. I removed the code from:
Private Sub GROnly_yes_Click()
And I moved it to the button that the user clicks to submit the form:
Private Sub ContinueButton_Click()
In my original code I had to change UserForm_Initialize to Exit Sub to make the code work in the "submit" button.
Thanks again for your help.
Phil

Can you set events within Tab Control for MS Access?

I have been searching the internet for this all day. But no luck.
Can you setup events for when you enter/leave a tab.
I.E.
OnExit(Tab1)
Do something
Thanks
Depending on your program flow, you might try:
Private Sub Combo3_Exit(Cancel As Integer)
If IsNull(Me.Combo3) Then
MsgBox "No exit"
Cancel = True
End If
End Sub
Private Sub Form_Current()
Me.Combo3.SetFocus
''Or to refer to a subform from the main form
Me.subformcontrolname.Form.Combo3.SetFocus
End Sub
Does the tab contain a subform or only controls from the main form?
A subform has an Exit event, so if you are only concerned that once you have entered the subform you should not leave without completing data, you could:
Private Sub subformcontrolname_Exit(Cancel As Integer)
If IsNull(Me.subformcontrolname.Form.Combo3) Then
Me.subformcontrolname.Form.Combo3.SetFocus
MsgBox "No exit"
Cancel = True
End If
End Sub
While this is not exactly what you want, you could instead of handling the exit simply prevent the user from clicking somewhere else. To do this, attach some code to your combobox1 that bascially set .Enabled=Xfor all elements outside your tab view - where X is determined by the state of the combobox...

Calling a macro from a button in edit mode while in PowerPoint

I'm trying to write a vba macro that can be called in edit-mode in PowerPoint 2007-2010.
I can easily add a Command Button to a presentation. However, this button can only be clicked to trigger the vba macro while in slideshow mode.
However, what I would like to do is have this button trigger the associated vba macro while in edit mode. Clicking on it in edit mode allows me to change its size etc, but it doesn't call the macro.
In Excel on the other hand, I get exactly the expected behaviour when I insert a button -> clicking on it calls the vba action.
So how can I create a button (or other element that acts the same way) that calls a vba macro during edit view in PowerPoint. The only way I can think of is using a ribbon action, however this is unpractical in this case, because the macro will modify a shape that is associated with the button and there might be several of these shapes per slide that should each have their own button.
The only way I can think of is using a ribbon action, however this is unpractical in this case, because the macro will modify a shape that is associated with the button and there might be several of these shapes per slide that should each have their own button.
Depending on what you're trying to do, a ribbon button that launches a macro might be quite practical. The macro could operate on the current selection (and test the current selection to ensure that it's something appropriate).
With ActiveWindow.Selection.ShapeRange
' operate on the currently selected shapes
End with
just answer it a some where else also
it is possible to do so all you need is download this file
http://www.officeoneonline.com/eventgen/EventGen20.zip
install it
create a class module
paste this code
Option Explicit
Public WithEvents PPTEvent As Application
Private Sub Class_Initialize()
End Sub
Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Type = ppSelectionShapes Then
If Sel.ShapeRange.HasTextFrame Then
If Sel.ShapeRange.TextFrame.HasText Then
If Trim(Sel.ShapeRange.TextFrame.TextRange.Text) = "Text inside your shape" Then
Sel.Unselect
yoursub
End If
End If
End If
End If
End Sub
insert a new module
paste this code
Dim cPPTObject As New Class1
Dim TrapFlag As Boolean
Sub TrapEvents()
If TrapFlag = True Then
MsgBox "Already Working"
Exit Sub
End If
Set cPPTObject.PPTEvent = Application
TrapFlag = True
End Sub
Sub ReleaseTrap()
If TrapFlag = True Then
Set cPPTObject.PPTEvent = Nothing
Set cPPTObject = Nothing
TrapFlag = False
End If
End Sub
Sub yoursub()
MsgBox "Your Sub is working"
End Sub
Now run TrapEvents and whenver you will click shape with that text in it your sub will run
Credits to the person who wrote this http://www.officeoneonline.com/eventgen/eventgen.html