I have 2 Option buttons.
The problem is, that when I click on one of them I can't execute of the process when clicking on the same option button again.
Could anyone tell me how to do it?
I found some threads here, but without solution:
https://social.msdn.microsoft.com/Forums/en-US/f942f0e2-3daf-4a06-a7c9-3904a88e49bc/macro-called-twice-on-single-button-click
I can also do the DoubleClick
Private Sub SchematicImage2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
But it doesn't solve my problem, because I want to have the result after one click and be able to click on the same button with code execution again. The button seems to be no longer active after one click. I don't want that.
How can I do this?
Try this DblClick event, please:
Private Sub SchematicImage2_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
MsgBox IIf(Me.SchematicImage2.value = True, "True", "False")
End Sub
Related
I want to trigger some event upon clicking certain options in listbox1. I can achieve this when listbox1 is set to SelectSingle. But when using fmMultiSelectMulti property, it does not work. Below is simple code I am using to test the clicking.
Private Sub ListBox1_Click()
If ListBox1.Selected(0) Then MsgBox "Nice"
End Sub
I click the first option and I thought it would trigger the MsgBox. Am I doing something wrong? How can I fix this?
Thanks
Edit: Using the change event worked!
I need to make a button which forwards me to the Print Preview page in Excel.
The annoying thing is, that the form with the button will stay open and I am also unable to interact with it directly (I can close the whole thing). So I can't move it out of the way to look at the preview or press any other button on the form.
I have already tried the .hide and .visible=false but neither of them worked. It spits out errors or won't make a difference at all.
Private Sub Drucken_IST_Click()
Worksheets("Bestand").PrintOut Preview:=True
End Sub
Have you tried to unload the form?
Here is an example of how to do it. Let me know if it works! :)
Option Explicit
Private Sub CommandButton1_Click()
Unload YourForm1 ' unload
Sheets("YourSheet").Select
YourForm1.Show
End Sub
I have a userform with 4 buttons.
I want to start the userform with button 1 already active.
The button is a public sub called "StartMeasButton_Click()" and is inside the userform. I need to click on that button.
I tried the Application.Run method but it fails, as I've understood, as the method is for a spreadsheet command button and not for a userform inside button.
Simplest solution: Make your button click call a subroutine, then you can call the subroutine whenever you want to "click" the button.
Sub StartMeasButton_Click()
MySubRoutine
End Sub
Sub MySubRoutine()
'put the body of your click routine here
End Sub
Sub Form1_Initialise
MySubRoutine 'effectively the same as clicking the button
End Sub
I am new to visual basic. I have a TextBox, and I want to trigger an event when the user lose focus on the textBox.
I tried writing
Private Sub TextBox_LostFocus()
something
End Sub
and
Private Sub TextBox_Leave()
something
End Sub
I don't really understand how they work, I have
Private Sub TextBox_Change()
something
End Sub
and that works fine, so what am I missing? How do I trigger the event when the user is not writing in the textbox anymore?
This is what you want:
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
End Sub
There's a helper -- when you're in the code editor, you'll see two list boxes above the editor. The list on the left contains the available objects for the current module. Select TextBox from there if it isn't already selected. The list box on the right contains the available Events. You should see Exit in there. Clicking that will paste in the code above.
I have a sheet with a custom button on it from where I control the printing process.
Now the user clicks on the menu bar's print icon and this produces an "undefined" output.
How can I intercept this menu bar button?
Thanks
Handle the Workbook_BeforePrint event.
private sub Workbook_BeforePrint (cancel as boolean)
'//g_MyFlag is set when the user clicks you toolbar button.
'//It must get cleared in the end of your procedure.
if not g_MyFlag then cancel = true: exit sub
end sub
In MS Word, it's also possible to redefine the system macro itself. You'd have to create a macro named FilePrint(), and Word would call it instead its own. A pity you can't do that in Excel.