When code is run, the ruler "flashes" briefly

B

Barb Reinhardt

I've done a lot of VBA in Excel, and I know there are ways to disable screen
updating there during execution. Is there a way to do this with Word?
I've got some code that when it runs, the ruler is "hidden" and then
redisplayed. It's very quick, but I want the execution of this code to be
transparent to the user.

Thanks in advance,
Barb Reinhardt
 
B

Barb Reinhardt

I thought I looked to see if there was a screenupdating in Word. I guess i
didn't. Anyway, that doesn't solve the problem. Any other ideas?
 
B

Barb Reinhardt

This is the code that's run. It's not as "elegant" as I'd like, but it works.

Option Explicit

Sub UpdateQuestions(myOptionButton As OptionButton)
Dim myQ As Long
Dim myA As Long
Dim myVal As String
Dim i As Long
Dim myDoc As Word.Document
Dim myFormField As Word.FormField
Dim myTotal As Word.FormField
Dim mySum As Long
Dim myArray() As Long
Dim myGroup As String
Dim myCount As Long

Application.ScreenUpdating = False
Set myDoc = ThisDocument

myVal = Replace(myOptionButton.Name, "OptionButton", "")
myGroup = myOptionButton.GroupName

myQ = Left(myVal, Len(myVal) - 1)
myGroup = Replace(myGroup, myQ, "")

If LCase(myGroup) Like "plannedvalue*" Then
myCount = 0
On Error Resume Next
myCount = UBound(QPlanVal)
On Error GoTo 0
If myQ >= myCount Then
ReDim Preserve QPlanVal(myQ)
End If

ReDim myArray(UBound(QPlanVal))
For i = 1 To UBound(QPlanVal)
myArray(i) = QPlanVal(i)
Next i
ElseIf LCase(myGroup) Like "finalvalue*" Then
myCount = 0
On Error Resume Next
myCount = UBound(QFinalVal)
On Error GoTo 0
If myQ >= myCount Then
ReDim Preserve QFinalVal(myQ)
End If

ReDim myArray(UBound(QFinalVal))
For i = 1 To UBound(QFinalVal)
myArray(i) = QFinalVal(i)
Next i
Else
MsgBox ("Need to define array to use for sums.")
Exit Sub
End If

myA = Right(myVal, 1)
myArray(myQ) = myA

mySum = 0
For i = 1 To UBound(myArray)
mySum = mySum + myArray(i)
Next i

If myGroup = "PlannedValue" Then
For i = 1 To UBound(QPlanVal)
QPlanVal(i) = myArray(i)
Next i
ElseIf myGroup = "FinalValue" Then
For i = 1 To UBound(QFinalVal)
QFinalVal(i) = myArray(i)
Next i
Else
'Shouldn't get here
MsgBox ("Need to define array to use for sums.")
Exit Sub
End If

Set myTotal = myDoc.FormFields(myGroup & "Total")
myTotal.Result = mySum
Application.ScreenUpdating = True

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top