VBA(Word):强制用户表单实时更新 [英] VBA (Word): force user form to update in real time

查看:244
本文介绍了VBA(Word):强制用户表单实时更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Word文件(Word 2016),带有大约. 750个字段.通过VBA宏,我分别更新了每个字段(.Fields(i).Update),以便能够创建一个穷人"进度条,向用户显示更新状态(已更新了多少个字段以及其中有多少个字段)总计):

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

问题在于,用户表单无法实时更新.前几个计数有效(大约直到i = 20),然后该用户表单不更新(大约直到i = 150),此后更新再次起作用.我已经尝试过:

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:

使用RepaintDoEvents

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]

使用单独的子

[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:

  • Update multiple fields with Excel links very slow
  • How to show the progress of the "Fields.Update"-Method in VBA (Word)

推荐答案

在某些情况下,这似乎是Windows/Office故障.当我遇到问题时,重新启动Office/Windows在某些(但不是全部)情况下解决了该问题.

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.

这篇关于VBA(Word):强制用户表单实时更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆