Quantcast
Channel: Word for Developers forum
Viewing all articles
Browse latest Browse all 4350

Speeding up Word Macro

$
0
0

I have a form - 12 questions (radio buttons) - each grouped with 4 questions.

Is there a better way to write this?   It's taking 40 seconds to open the file.   Also each radio button has it's own sub pointing to the "total" below...   The form is dynamic and works well, but the open time is too long... 

Private Sub Total()
'OB = radio buttons corrispond to OptionButton# (5 per line)
Dim ob01, ob02, ob03, ob04, ob05, ob06, ob07, ob08, ob09, ob10, ob11, ob12, ob13, ob14, ob15, ob16, ob17, ob18, ob19, ob20, ob21, ob22, ob23, ob24, ob25, ob26, ob27, ob28, ob29, ob30, ob31, ob32, ob33, ob34, ob35, ob36, ob37, ob38, ob39, ob40, ob41, ob42, ob43, ob44, ob45, ob46, ob47, ob48, ob49, ob50, ob51, ob52, ob53, ob54, ob55, ob56, ob57, ob58, ob59, ob60 As Byte

 

'LT = Line Totals
Dim LT1, LT2, LT3, LT4, LT5, LT6, LT7, LT8, LT9, LT10, LT11, LT12 As Single

'ST = Subtotals
Dim ST1, ST2, ST3 As Single

'AL = Asigned Level Text Boxes 1-12
Dim AL1, AL2, AL3, AL4, AL5, AL6, AL7, AL8, AL9, AL10, AL11, AL12 As Single

'W = Weight - input from user text box
Dim w1, w2, w3, w4, w5, w6, w7, w8, w9, w10, w11, w12 As Single

'Assigned values for each radio button
ob01 = Abs(Int(Me.OptionButton1.Value)) * 0 'Group 1 - Radio Button Group CMP1
ob02 = Abs(Int(Me.OptionButton2.Value)) * 1
ob03 = Abs(Int(Me.OptionButton3.Value)) * 2
ob04 = Abs(Int(Me.OptionButton4.Value)) * 3
ob05 = Abs(Int(Me.OptionButton5.Value)) * 4
ob06 = Abs(Int(Me.OptionButton6.Value)) * 0 'Group 2 - Radio Button Group CMP2
ob07 = Abs(Int(Me.OptionButton7.Value)) * 1
ob08 = Abs(Int(Me.OptionButton8.Value)) * 2
ob09 = Abs(Int(Me.OptionButton9.Value)) * 3
ob10 = Abs(Int(Me.OptionButton10.Value)) * 4
ob11 = Abs(Int(Me.OptionButton11.Value)) * 0 'Group 3 - Radio Button Group CMP3
ob12 = Abs(Int(Me.OptionButton12.Value)) * 1
ob13 = Abs(Int(Me.OptionButton13.Value)) * 2
ob14 = Abs(Int(Me.OptionButton14.Value)) * 3
ob15 = Abs(Int(Me.OptionButton15.Value)) * 4
ob16 = Abs(Int(Me.OptionButton16.Value)) * 0 'Group 4 - Radio Button Group CMP4
ob17 = Abs(Int(Me.OptionButton17.Value)) * 1
ob18 = Abs(Int(Me.OptionButton18.Value)) * 2
ob19 = Abs(Int(Me.OptionButton19.Value)) * 3
ob20 = Abs(Int(Me.OptionButton20.Value)) * 4
ob21 = Abs(Int(Me.OptionButton21.Value)) * 0 'Group 5 - Radio Button Group CMP5
ob22 = Abs(Int(Me.OptionButton22.Value)) * 1
ob23 = Abs(Int(Me.OptionButton23.Value)) * 2
ob24 = Abs(Int(Me.OptionButton24.Value)) * 3
ob25 = Abs(Int(Me.OptionButton25.Value)) * 4
ob26 = Abs(Int(Me.OptionButton26.Value)) * 0 'Group 6 - Radio Button Group CMP6
ob27 = Abs(Int(Me.OptionButton27.Value)) * 1
ob28 = Abs(Int(Me.OptionButton28.Value)) * 2
ob29 = Abs(Int(Me.OptionButton29.Value)) * 3
ob30 = Abs(Int(Me.OptionButton30.Value)) * 4
ob31 = Abs(Int(Me.OptionButton31.Value)) * 0 'Group 7 - Radio Button Group CMP7
ob32 = Abs(Int(Me.OptionButton32.Value)) * 1
ob33 = Abs(Int(Me.OptionButton33.Value)) * 2
ob34 = Abs(Int(Me.OptionButton34.Value)) * 3
ob35 = Abs(Int(Me.OptionButton35.Value)) * 4
ob36 = Abs(Int(Me.OptionButton36.Value)) * 0 'Group 8 - Radio Button Group CMP8
ob37 = Abs(Int(Me.OptionButton37.Value)) * 1
ob38 = Abs(Int(Me.OptionButton38.Value)) * 2
ob39 = Abs(Int(Me.OptionButton39.Value)) * 3
ob40 = Abs(Int(Me.OptionButton40.Value)) * 4
ob41 = Abs(Int(Me.OptionButton41.Value)) * 0 'Group 9 - Radio Button Group CMP9
ob42 = Abs(Int(Me.OptionButton42.Value)) * 1
ob43 = Abs(Int(Me.OptionButton43.Value)) * 2
ob44 = Abs(Int(Me.OptionButton44.Value)) * 3
ob45 = Abs(Int(Me.OptionButton45.Value)) * 4
ob46 = Abs(Int(Me.OptionButton46.Value)) * 0 'Group 10 - Radio Button Group CMP10
ob47 = Abs(Int(Me.OptionButton47.Value)) * 1
ob48 = Abs(Int(Me.OptionButton48.Value)) * 2
ob49 = Abs(Int(Me.OptionButton49.Value)) * 3
ob50 = Abs(Int(Me.OptionButton50.Value)) * 4
ob51 = Abs(Int(Me.OptionButton51.Value)) * 0 'Group 11 - Radio Button Group CMP11
ob52 = Abs(Int(Me.OptionButton52.Value)) * 1
ob53 = Abs(Int(Me.OptionButton53.Value)) * 2
ob54 = Abs(Int(Me.OptionButton54.Value)) * 3
ob55 = Abs(Int(Me.OptionButton55.Value)) * 4
ob56 = Abs(Int(Me.OptionButton56.Value)) * 0 'Group 12 - Radio Button Group CMP12
ob57 = Abs(Int(Me.OptionButton57.Value)) * 1
ob58 = Abs(Int(Me.OptionButton58.Value)) * 2
ob59 = Abs(Int(Me.OptionButton59.Value)) * 3
ob60 = Abs(Int(Me.OptionButton60.Value)) * 4

'Assigned Value for each question
AL1 = ob01 + ob02 + ob03 + ob04 + ob05
AL2 = ob06 + ob07 + ob08 + ob09 + ob10
AL3 = ob11 + ob12 + ob13 + ob14 + ob15
AL4 = ob16 + ob17 + ob18 + ob19 + ob20
AL5 = ob21 + ob22 + ob23 + ob24 + ob25
AL6 = ob26 + ob27 + ob28 + ob29 + ob30
AL7 = ob31 + ob32 + ob33 + ob34 + ob35
AL8 = ob36 + ob37 + ob38 + ob39 + ob40
AL9 = ob41 + ob42 + ob43 + ob44 + ob45
AL10 = ob46 + ob47 + ob48 + ob49 + ob50
AL11 = ob51 + ob52 + ob53 + ob54 + ob55
AL12 = ob56 + ob57 + ob58 + ob59 + ob60


'Weight value for each question
w1 = Abs(Int(Me.TextBox2.Value))
w2 = Abs(Int(Me.TextBox5.Value))
w3 = Abs(Int(Me.TextBox8.Value))
w4 = Abs(Int(Me.TextBox11.Value))
w5 = Abs(Int(Me.TextBox14.Value))
w6 = Abs(Int(Me.TextBox17.Value))
w7 = Abs(Int(Me.TextBox20.Value))
w8 = Abs(Int(Me.TextBox23.Value))
w9 = Abs(Int(Me.TextBox26.Value))
w10 = Abs(Int(Me.TextBox29.Value))
w11 = (Int(Me.TextBox32.Value))
w12 = (Int(Me.TextBox35.Value))

'Calculation of Line Totals
LT1 = AL1 * w1
LT2 = AL2 * w2
LT3 = AL3 * w3
LT4 = AL4 * w4
LT5 = AL5 * w5
LT6 = AL6 * w6
LT7 = AL7 * w6
LT8 = AL8 * w8
LT9 = AL9 * w9
LT10 = AL10 * w10
LT11 = AL11 * w11
LT12 = AL12 * w12

'Calculation of Subtotals
ST1 = LT1 + LT2 + LT3 + LT4 + LT5 + LT6 + LT7 + LT8 + LT9 + LT10
ST2 = LT11 + LT12
ST3 = ST1 + ST2

'Values for the Assigned Level and Weight Level
Me.TextBox1.Value = AL1
Me.TextBox3.Value = LT1
Me.TextBox4.Value = AL2
Me.TextBox6.Value = LT2
Me.TextBox7.Value = AL3
Me.TextBox9.Value = LT3
Me.TextBox10.Value = AL4
Me.TextBox12.Value = LT4
Me.TextBox13.Value = AL5
Me.TextBox15.Value = LT5
Me.TextBox16.Value = AL6
Me.TextBox18.Value = LT6
Me.TextBox19.Value = AL7
Me.TextBox21.Value = LT7
Me.TextBox22.Value = AL8
Me.TextBox24.Value = LT8
Me.TextBox25.Value = AL9
Me.TextBox27.Value = LT9
Me.TextBox28.Value = AL10
Me.TextBox30.Value = LT10
Me.TextBox31.Value = AL11
Me.TextBox33.Value = LT11
Me.TextBox34.Value = AL12
Me.TextBox36.Value = LT12
Me.TextBox37.Value = ST1
Me.TextBox38.Value = ST2
Me.TextBox39.Value = ST3

End Sub


Viewing all articles
Browse latest Browse all 4350

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>