clear textbox when click commandbutton with checkbox clicked-VBA - vba

I'm wondering how to do clear textboxes when click commandbutton1 with checkbox1 clicked, because it seems to be impossible to do like this
when clicking the commandbutton and the checkbox is checked, i want to clean those textboxes

Try this:
Private Sub CommandButton1_Click()
If CheckBox1 Then
TextBox1.Value = ""
End If
End Sub

Related

How to implement a Cancel button on a userform?

I have a UserForm with a cancel button.
Sub DialogTest()
MyForm.Show
End Sub
Private Sub CancelButton_Click()
Unload Me
End
End Sub
I also tried MyForm.Hide, End by itself, cmdExit_Click.
The cancel button does not close the dialog nor does it cause the debugger to come up.
I was only able to replicate your issue when the Unload Me Sub was pasted in a Worksheet or Module. When the Sub is in the Userform, it works fine.
Here, the code is pasted in a module and does not close the Userform
Instead, from VBE, double click on your UserForm, then double click on your Cancel Button.
Then paste the code here

How to dynamically edit a excel vba form label and tab label?

I have an excel vba form which has some tabs(pages).What I need is, if I double click on label, it should be editable. same is the case for the tabs.
I tried to add some things into the double click function, but not showing any change.
Labels are not editable by the end user
you may adopt this workaround
'change "Label1" occurrences to your actual label name
Private Sub Label1_DblClick()
Me.Label1.Caption = Application.InputBox("enter label text", "label editing", "")
End Sub
You can have a TextBox and disable it. The side effect is you will have textbox edit cursor over the label.
Have two subroutines, one called Labelize and another Textboxize. The former locks the textbox, makes it tranparent, and sets the 3D effect to flat. The latter unlocks it, makes it opaque, and sets the 3D to sunken (the default).
' Makes a textbox look like a label
Private Sub Labelize(txtbox As MSForms.TextBox)
txtbox.Locked = True
txtbox.BackStyle = fmBackStyleTransparent
txtbox.SpecialEffect = fmSpecialEffectFlat
End Sub
' Makes a textbox look like a textbox
Private Sub Textboxize(txtbox As MSForms.TextBox)
txtbox.Locked = False
txtbox.BackStyle = fmBackStyleOpaque
txtbox.SpecialEffect = fmSpecialEffectSunken
End Sub
In the form initialize event set call the Labelize method passing in your textboxes.
Private Sub UserForm_Initialize()
Labelize Me.txtExample
End Sub
In the double-click event per textbox, call the Textboxize method passing in your textbox again.
Private Sub txtExample_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Textboxize Me.txtExample
End Sub
Then in each KeyDown event, check if the key pressed was enter then call the Labelize method.
Private Sub txtExample_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 13 Then Labelize Me.txtExample
End Sub

Excel VBA Custom dialog box cancel button code

I have a dialog box pop up with radio buttons, the radio buttons currently run macros. However, once I have the dialog box pop I can't close it. I have added a cancel button. The code is below
Private Sub CommandButton1_Click()
Cmd_Cancel
End Sub
How can I get my dialog box to close by pressing the cancel button?
In my form I used a Cancel button with the below code for it
btnCancel is the (Name) of the button
Private Sub btnCancel_Click()
Unload Form_Form1
End Sub
Depends on what you want. The keyword "Me" is the actual instance of the Form-Object. Hide it and its still in the memory. Or unload it to kill it:
When it's only hidden you can show it again with .show (from another piece of code...)
Private Sub CommandButton1_Click()
Me.Hide
Unload Me
End Sub

open a sheet checkbox is checked with vba excel

how I can check if a checkbox is selected ?
And after selecting a checkbox for example "a" (in my example) I want to open a excel sheet.
How can I solve this problem?
Thank you all.
In the UserForm module you can just place the following code, when your CheckBox is named "CheckBox1":
Private Sub CheckBox1_Click()
If Me.CheckBox1.Value = True Then
Worksheets("Sheet1").Visible = True
Else
Worksheets("Sheet1").Visible = False
End If
End Sub
This will make "Sheet1" visible when it's checked and invisible when unchecked.
If you name your checkbox differently, you'll see that if you double click the checkbox in the Userform Design, the VBE will already come up with
Private Sub CheckBoxName_Click()
End Sub

VBA to change the name of the Activex button

I am not sure, even if this is possible. I would like to change the named of the button when clicked.
I have Active X button that will enable cells on the sheet when clicked. Name of the button "Enable Sheet".
Once he enables, he should see a button "Disable Sheet". Please advise.
assuming your button is named after "CommandButton1":
Private Sub CommandButton1_Click()
With Me.OLEObjects("CommandButton1").Object
.Caption = IIf(.Caption = "Enable Sheet", "Disable Sheet", "Enable Sheet")
End With
End Sub
edited after OP's comments
Private Sub CommandButton1_Click()
With Me.OLEObjects("CommandButton1").Object
.Caption = IIf(.Caption = "Enable", "Disable", "Enable")
Range("E13:E14").Locked = .Caption = "Enable"
End With
End Sub
In the code that you can attach to the ActiveX object, you can try something like this:
Private Sub CommandButton1_Click()
Me.CommandButton1.Caption = "Enable"
End Sub
In general, for ActiveX Objects, you can change the displayed text using the .Caption property.