Is it possible to add up/down arrow beside the text boxes (spinner) to adjust the height and width of an object by clicking with a mouse?
Hello, everybody,
I will suggest a macro codeYou must have:- a not modale userform- controls on userform: - tbWidth - text box - tbHeight - text box - tbStep - text box - SpinButton1
Code UserForm_Activate:SpinButton1.Enabled = FalseOn Error Resume NexttbHeight.Value = Val(ActiveShape.SizeHeight * 25.4)On Error Resume NexttbWidth.Value = Val(ActiveShape.SizeWidth * 25.4)tbStep.Value = 1---------------------------------------------------------------------------------
Private Sub GlobalMacroStorage_SelectionChange()On Error Resume NextufCommands.tbWidth.Value = ActiveShape.SizeWidth * 25.4 'my units are millimetersOn Error Resume NextufCommands.tbHeight.Value = ActiveShape.SizeHeight * 25.4End Sub---------------------------------------------------------------------------------Private Sub tbWidth_Enter()SpinButton1.Enabled = TrueacName = ActiveControl.NameEnd Sub---------------------------------------------------------------------------------Private Sub tbHeight_Enter()SpinButton1.Enabled = TrueacName = ActiveControl.NameEnd Sub---------------------------------------------------------------------------------Private Sub SpinButton1_SpinDown()'MsgBox acNameMe.Controls(acName).Value = Val(Me.Controls(acName).Value) - Val(tbStep.Value)If acName = "tbWidth" ThenActiveShape.SizeWidth = Val(Me.Controls(acName).Value) / 25.4End IfIf acName = "tbHeight" ThenActiveShape.SizeHeight = Val(Me.Controls(acName).Value) / 25.4End If'tbHeight.Value = tbHeight.Value - 1'MsgBox acNameEnd SubPrivate Sub SpinButton1_SpinUp()'MsgBox acName'tbHeight.Value = tbHeight.Value + 1Me.Controls(acName).Value = Val(Me.Controls(acName).Value) + Val(tbStep.Value)If acName = "tbWidth" ThenActiveShape.SizeWidth = Val(Me.Controls(acName).Value) / 25.4End IfIf acName = "tbHeight" ThenActiveShape.SizeHeight = Val(Me.Controls(acName).Value) / 25.4End IfEnd SubAt declaration level of UserForm:Public acName As StringA little code explanation:When UserForm is activated SpinButton1 is disabledA click with mouse in tbWidth or tbHeight will enable SpiButton1 and acName=ActiveControl.name 'tbWidth or tbHeightSpinUp/SpinDown will change values in acName control 'tbWidth or tbHeight with value of tbStep.value 'default is 1, see UserForm_Activate aboveThe code below make it possible to select difrent shapes when modeless UserForm is open. Put actual size values of selected/active shape in tbWidth and tbHeight. Changing of size with tbStep.value Up/Down is possible for each active shape.Private Sub GlobalMacroStorage_SelectionChange()On Error Resume NextufCommands.tbWidth.Value = ActiveShape.SizeWidth * 25.4On Error Resume NextufCommands.tbHeight.Value = ActiveShape.SizeHeight * 25.4End SubBetter code can certainly be written. Greetings!