SpinButton To Change a Variable in a Running Macro ? / MS Word

KenWit

Board Regular
Joined
Nov 21, 2011
Messages
68
Is there a way increase or decrease a variable in a running macro on a userform with a spinbutton on a userform.

e.g. the value of X which controls the speed of a macro . . .

Private Sub CommandButton1_Click ()
For Each w In Selection.Words
w.Font.bold = True
For i = 1 To X [default X = 1000] / spinbutton1.value
Debug.Print i
Next i
w.Font.bold = False
Next w
End Sub

. . . by using a spinbutton, so that when a user clicks the spinbutton the value of X changes in the running macro and its accorded speed? (So words in a document are bolded faster or slower.)

I couldn't even begin to guess how this might be done, if it's even possible? :confused:
 
Last edited:

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Where/when do you currently set the value of X?
 
Upvote 0
Both places. In the properties of the spinbutton and in the macro, X = 1000, (So the spinbutton starts out at the same place.)
 
Upvote 0
Simple solution, if anyone is interested. You just code the spinbutton like this:

Private Sub SpinButton1_Change()
Static X As Integer
X = SpinButton1.Value
End Sub

Then stick "X = SpinButton1.Value" into your macro in several different places so no matter when you click the code will fetch the value.

One last thing is to set the Delay in the SpinButton's property to 0, so it acts immediately.

It's not a perfect solution. The spinbutton acts a bit oddly at times creating more of a change in value than it is set for.
But it does more or less work.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top