excel - 移动带有插入行的形状,其中 Application.ScreenUpdating = False
问题描述
在一个大型项目中,我在工作表的不同位置添加了大量形状。此外,我插入了许多行。
我希望形状与插入的行一起移动。但是,他们只使用Application.ScreenUpdating = True
. 一旦设置 ScreenUpdating False
,形状就会停止移动。这当然会完全弄乱结果。
我无法重现该问题。在这个最小的示例中,插入的形状会随着插入的行按预期移动,尽管我使用Application.ScreenUpdating = False
. 在我较大的程序中,基本相同的程序在没有 ScreenUdating 的情况下失败。
Sub ShapeTest()
Dim ActiveShape As Shape
Dim ShapeCell As Range
Application.ScreenUpdating = False
Set ShapeCell = ActiveSheet.Range("A1")
Set ActiveShape = ActiveSheet.Shapes.AddShape(msoShapeRectangle, ShapeCell.Left, ShapeCell.Top, ShapeCell.Width, ShapeCell.Height)
ActiveSheet.Rows(1).Insert shift:=xlShiftDown
Application.ScreenUpdating = True
End Sub
更新
我DoEvents
在插入行之前和之后都尝试过,但它没有改变任何东西。目前我正在使用这种解决方法:
Application.ScreenUpdating = True
Worksheets("Gantt").Rows(ThisRowGTT).Insert shift:=xlShiftDown
Application.ScreenUpdating = False
这会减慢执行速度——几乎就像我会为整个程序使用 ScreenUpdating 一样。
解决方案
推荐阅读
- c# - 如何使用用户输入的开始日期和结束日期更新结果
- android - 有什么方法可以自定义 Accessibility 重点节点上的 Talkback 突出显示的矩形?
- rabbitmq - 如何从客户端重试 Rabbit MQ 中的消息?
- angular - 配置 Angular 以将 .mrt 文件作为 XML 读取,以修复错误“Unexpected token < in JSON”
- swift - 如何删除文本框边框
- android - 使用 FileProvider 发送带附件的电子邮件
- ews-javascript-api - ews-javascript-api 可以在标准 Web 应用程序中使用并通过 Chrome 访问吗?
- c++ - 为什么混合 -fexceptions 和 -fno-exceptions 没有链接器警告
- keras - 为卷积神经网络 (Keras) 重塑二维数据
- angular - (Angular 6)FullCalendar 未正确加载