简体   繁体   English

Excel 在 VBA 中使用 SmartArtLayout 时运行缓慢?

[英]Excel keeps running slow using SmartArtLayout in VBA?

Excel freezes when this code is ran, is there a way of stopping this?运行此代码时 Excel 冻结,有没有办法阻止它? or even making it freeze for less time.甚至让它冻结更短的时间。 The code generates a smart art hierarchy代码生成智能艺术层次结构

Sub Org()
'
' Org Macro
'
    Dim ogSALayout As SmartArtLayout
    Dim QNode As SmartArtNode
    Dim QNodes As SmartArtNodes
    Dim t As Integer
    Set ogSALayout = Application.SmartArtLayouts(105) 'reference to organization chart
    Set ogShp = ActiveWorkbook.ActiveSheet.Shapes.AddSmartArt(ogSALayout)
    Set QNodes = ogShp.SmartArt.AllNodes
    t = QNodes.Count

    While QNodes.Count < t
    QNodes(QNodes.Count).Delete
    Wend

    While QNodes.Count < Range("A1").End(xlDown).Row
    QNodes.Add.Promote
    Wend

    For i = 1 To Range("A1").End(xlDown).Row
    'Promote and demote nodes to put them at the proper level.

    While QNodes(Range("A" & i)).Level < Range("C" & i).Value
        QNodes(Range("A" & i)).Demote
    Wend

    'Copy the cell text to the node.
    QNodes(Range("A" & i)).TextFrame2.TextRange.Text = Range("B" & i)
    Next i

End Sub

This might help:这可能会有所帮助:

 Sub Org()
 Application.Screenupdating = False

 'the rest of your code

 Application.Screenupdating = True
 End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM