0
votes

I have a word file (Word 2016) with approx. 750 fields. Through a VBA macro I update each field separately (.Fields(i).Update) in order to be able to make a "poor men's" progress bar showing the user the status of the update (how many fields have been updated and how many fields there are in total):

'Select Storyrange (first section)
Dim rngRange as Range
rngRange = ThisDocument.StoryRanges(wdMainTextStory)
Dim intFields as Integer
intFields = rngRange.Fields.Count

'Show Form
UserForm1.Show vbModeless

'Update each field individually
For i = 1 To intFields 
    'Update Field
    rngRange.Fields(i).Update
    'Update User Form
    UserForm1.Label1.Caption = i & "/" & intFields 
Next i

The problem is, that the user form does not get updated in real time. The first few counts work (approx. until i = 20), then there user form doesn't update (approx. until i = 150), after that the update works again. I already tried:

use Repaint and DoEvents

[snip]
'Update User Form
UserForm1.Label1.Caption = i & "/" & intFields 
Repaint
DoEvents
Application.ScreenRefresh 'just to be save, since - in my view - ScreenRefresh only effects the Word window, not the user form
[snip]

use a separate sub

[snip]
'Update User Form
updateUserform i, intFields
[snip]

Dim updateUserform(i as Integer, intFields as Integer)
    UserForm1.Label1.Caption = i & "/" & intFields 
    Repaint
    DoEvents
End Sub

So my question is: are there any other option to force a user form update?

Please Note: I also posted two other questions within this context:

1
Can't you use Application.ScreenRefresh before resuming your iteration through intFields?JvdV
@JvdV yes, I tried Application.ScreenRefresh but it did not work. And as far as I know only applies to the word window, it has no effect on the user form?! That's why I did not mention it in my solutions.Albin
Ah right, well I have very limited word-vba experience. Will come back in case I do find a solution for you. What I do know is that the macro is too fast for the repaint to keep up, at least that's what happens within Excel macro's.JvdV
@JvdV I'm not completely sure... ScreenRefresh includes Repaint, but I'm not really sure I would test this. Anyway it's not a solution that works in my case - for whatever reasons.Albin

1 Answers

0
votes

Seems in some case it is a Windows/Office glitch. Restarting Office/Windows solved the problem in some (but not all) cases when I encountered the problem.