![]() |
#1
|
|||
|
|||
![]()
Hey guys, this is my first post here! I'm a high school physics teacher in my 2nd year and i'm getting tired of the amount of copying that is happening in my Honors Physics class. I'd like to make a VBA macro that will randomize numbers on every copy i print for tests/worksheets. I use word 2016 at home and work.
Something where i could type a problem like this "Billy dropped a rock off a X meter high cliff. The rock has a mass of Y kilograms" And then when i print it i could print up 130 copies and word would automatically insert a random number within a designated range on each copy for the X and Y above. Below is what i have so far in code but i don't think it'll do the trick. Any advice? Thanks!!! Option Explicit Public Function RandomNumber(Lowest As Long, Highest As Long, _ Optional Decimals As Integer) If IsMissing(Decimals) Or Decimals = 0 Then Randomize RandomNumber = Int((Highest + 1 - Lowest) * Rnd + Lowest) Else Randomize RandomNumber = Round((Highest - Lowest) * Rnd + Lowest, Decimals) End If End Function Sub RNG1to10() Dim rn1 As Double Dim text As Double rn1 = RandomNumber(1, 10, 0) Selection.TypeText text:=rn1 End Sub |
Tags |
word 2016 |
|