添加复选框,加速过程

时间:2014-03-16 17:21:44

标签: performance excel excel-vba vba

我为我的Excel文档创建了一个VBA脚本,以便在另一个工作表中的特定单元格中创建各种Checkbox。

这很有效,但是"脚本"的运行时间。很慢.. 我想如果有办法加快这个过程。 我可以看到剧本从一张纸到另一张纸 - 猜测这也会减慢它的速度吗?

我怎样才能加快速度?

        ' Add checkboxes
           Set PasteLineCheckbox = PasteLineStart.Offset(12, 0)

               ' Aftale Checkboxes
               With .OLEObjects.Add(ClassType:="Forms.Checkbox.1", link:=False, DisplayAsIcon:=False, Left:=PasteLineCheckbox.Offset(0, 0).Left + 3, Top:=PasteLineCheckbox.Offset(0, 0).Top + 1, Width:=224.25, Height:=13.5)
                   .Object.Caption = "Timeaftale": .Placement = xlMoveAndSize: .LinkedCell = PasteLineCheckbox.Offset(0, 0).Address: .Object.Value = False: .Object.BackStyle = 0: .Object.SpecialEffect = 0: .Object.Font.Size = 10: .Object.Font.Bold = True
               End With
               With .OLEObjects.Add(ClassType:="Forms.Checkbox.1", link:=False, DisplayAsIcon:=False, Left:=PasteLineCheckbox.Offset(1, 0).Left + 3, Top:=PasteLineCheckbox.Offset(1, 0).Top + 1, Width:=224.25, Height:=13.5)
                   .Object.Caption = "Forretningsføreraftale": .Placement = xlMoveAndSize: .LinkedCell = PasteLineCheckbox.Offset(1, 0).Address: .Object.Value = False: .Object.BackStyle = 0: .Object.SpecialEffect = 0: .Object.Font.Size = 10: .Object.Font.Bold = True
               End With
               With .OLEObjects.Add(ClassType:="Forms.Checkbox.1", link:=False, DisplayAsIcon:=False, Left:=PasteLineCheckbox.Offset(2, 0).Left + 3, Top:=PasteLineCheckbox.Offset(2, 0).Top + 1, Width:=224.25, Height:=13.5)
                   .Object.Caption = "Anlægsbudget": .Placement = xlMoveAndSize: .LinkedCell = PasteLineCheckbox.Offset(2, 0).Address: .Object.Value = False: .Object.BackStyle = 0: .Object.SpecialEffect = 0: .Object.Font.Size = 10: .Object.Font.Bold = True
               End With

               ' Status Checkboxes
               With .OLEObjects.Add(ClassType:="Forms.Checkbox.1", link:=False, DisplayAsIcon:=False, Left:=PasteLineCheckbox.Offset(0, 2).Left + 3, Top:=PasteLineCheckbox.Offset(0, 2).Top + 1, Width:=224.25, Height:=13.5)
                   .Object.Caption = "Ønske": .Placement = xlMoveAndSize: .LinkedCell = PasteLineCheckbox.Offset(0, 2).Address: .Object.Value = False: .Object.BackStyle = 0: .Object.SpecialEffect = 0: .Object.Font.Size = 10: .Object.Font.Bold = True
               End With
               With .OLEObjects.Add(ClassType:="Forms.Checkbox.1", link:=False, DisplayAsIcon:=False, Left:=PasteLineCheckbox.Offset(1, 2).Left + 3, Top:=PasteLineCheckbox.Offset(1, 2).Top + 1, Width:=224.25, Height:=13.5)
                   .Object.Caption = "Pågår, Internt (Igang)": .Placement = xlMoveAndSize: .LinkedCell = PasteLineCheckbox.Offset(1, 2).Address: .Object.Value = False: .Object.BackStyle = 0: .Object.SpecialEffect = 0: .Object.Font.Size = 10: .Object.Font.Bold = True
               End With

提前感谢您提供帮助以加快速度! :)

1 个答案:

答案 0 :(得分:0)

有一点可以加快它的速度,确保在开始时放置:application.screenUpdating = false。这段代码使得屏幕不会显示正在发生的事情,所以你不会看到它发生。添加此代码将显着提高速度。