我正在尝试让Visio在我更改每个形状后立即更新它的填充颜色。
我尝试过使用不同的方法--屏幕更新,显示变化,发送键"%^g“,但是颜色都不起作用。只有将屏幕尺寸更改0.01%才会强制应用程序更改文本,这至少是有意义的。
我可以单步执行代码,它可以工作,但当我运行它时,直到最后颜色都不会改变。
我使用以下命令更改每个对象的颜色:
Application.ActiveWindow.Page.Shapes.ItemFromID(servshape(y - 1)).CellsU("Fillforegnd").FormulaU = "RGB(253, 190, 0)"
代码遍历日期列表,并在需要时更改对象的颜色,问题是它只在末尾显示更改。
遍历列表中的每一项的循环大约是一秒钟,足以看到任何更改。我希望有一个简单的刷新命令,但这似乎只适用于数据记录集。
有什么方法可以在更改对象填充颜色后立即刷新它吗?
发布于 2019-06-29 01:01:10
应与DoEvents:配合使用
Option Explicit
Sub reColorAll()
Dim pg As Visio.Page
'Set pg = Application.ActiveWindow.Page
Set pg = ActivePage ' Probably what you want
Dim shp As Visio.Shape
For Each shp In pg.Shapes
If True Then 'test if shape is one of the ones you want, replace true with test
If shp.CellExistsU("Fillforegnd", False) Then 'test if cell even exists
shp.CellsU("Fillforegnd").FormulaU = "RGB(253, 190, 0)"
DoEvents' force Application to update
End If
'Timer to simulate delay, can be removed for your case
Dim pauseTime As Long
Dim start As Long
pauseTime = 1 ' Set duration in seconds
start = Timer ' Set start time.
Do While Timer < start + pauseTime
Loop
'End Timer Code
End If
Next shp
End Sub
https://stackoverflow.com/questions/56809118
复制相似问题