EXCEL VBAでの質問です。

作成したいシートにチェックボックスか、マーク系(文字)かを表示する速度を測りました。
結果的には、チェックボックスで表示させると、多大な時間が掛かることが分かりました。
EXCEL2007で実行すれば処理速度に問題は無いのですが、EXCEL2013では遅すぎたり、止まったりする現象が発生します。
EXCELの拡張子を変えてみたり、色々と試しては見ましたが、まだ解決には至りませんでした。
実行最初の速度は変わらないように見えますが、100件を超えた位からチェックボックス表示での速度が落ちてきます。
一応、考えられる画面の表示をしないとかのはやってみましたが、EXCELのバージョンで凄く速度の違いと動作しなくなるパターンが発生します。
この辺の動きについて、何か情報が無いかと思ってます。
テスト用のVBA部分を提出します。

回答の条件
  • 1人5回まで
  • 登録:
  • 終了:2017/03/22 19:10:03
id:tatsuya-kawaguchi

Option Explicit

Private refWbk As Workbook

Private refWks As Worksheet

Private outWks As Worksheet

Private chkBoxRange As Range

Private chkBox As Object

Private flagDisplay As Integer

Sub printExecute()

If MsgBox("印刷処理を実行しますか。", vbYesNo + vbQuestion, "確認") = vbNo Then

Exit Sub

End If

Dim StartTime, StopTime, KeikaTime As Variant

'-----------------------------------------------------------------

'--- 表示形式:1:マーク形式, 2:チェックボックス形式

'-----------------------------------------------------------------

flagDisplay = 2

'-----------------------------------------------------------------

Set refWbk = ThisWorkbook

Worksheets.Add

ActiveSheet.Name = "Print"

Set outWks = ActiveSheet

'--- EXCEL高速化処理対応

Application.DisplayAlerts = False

Application.ScreenUpdating = False

Application.EnableEvents = False

Application.Calculation = xlCalculationManual

DoEvents

'

StartTime = Time

Debug.Print "-- start :" & Time

Dim nextLine As Long

nextLine = 1

Dim i As Long

Dim inpRecCount As Long

'---------------------------------------------------------------------------

inpRecCount = 1000

For i = 1 To inpRecCount

'---------------------------------------------------------------------------

DoEvents

Application.StatusBar = "■処理件数:" & i & " / " & inpRecCount

If flagDisplay = 1 Then

outWks.Range("A" & nextLine).Value = "■"

outWks.Range("B" & nextLine).Value = "□"

outWks.Range("C" & nextLine).Value = "■"

outWks.Range("D" & nextLine).Value = "□"

outWks.Range("E" & nextLine).Value = "■"

outWks.Range("F" & nextLine).Value = "□"

Else

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("A" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = True

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("B" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = False

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("C" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = True

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("D" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = False

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("E" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = True

Set chkBoxRange = Nothing

Set chkBox = Nothing

DoEvents

Set chkBoxRange = outWks.Range("F" & nextLine)

Set chkBox = outWks.CheckBoxes.Add(Left:=chkBoxRange.Left, Top:=chkBoxRange.Top, Width:=chkBoxRange.Width, Height:=chkBoxRange.Height)

chkBox.Caption = ""

chkBox.Value = False

End If

DoEvents

nextLine = nextLine + 1

Next i

StopTime = Time

Debug.Print "-- end :" & Time

KeikaTime = StartTime - StopTime

Debug.Print "-- Keika :" & Hour(KeikaTime) & "時間" & Minute(KeikaTime) & "分" & Second(KeikaTime) & "秒"

Application.Cursor = xlDefault

MsgBox "印刷処理終了。", vbInformation, "通知"

'--- EXCEL高速対応の解放

Application.DisplayAlerts = True

Application.Calculation = xlCalculationAutomatic

Application.ScreenUpdating = True

Application.StatusBar = ""

Application.StatusBar = False

End Sub

回答0件)

回答はまだありません

  • id:ken3memo
    https://answers.microsoft.com/ja-jp/office/forum/office_2010-excel/excel2000vba%E3%81%A7%E4%BD%9C%E6%88%90%E3%81%97/c5246736-08b1-4059-a144-7095f2e10655

    が似た現象だと思いますが、解決していないみたいです。
    テストやチェック方法、別角度のアプローチ、改善案の参考になればと思い、コメントします。
    ※余計な情報で、解決から離れてしまったらスミマセン、参考程度に読んでみてください。

この質問への反応(ブックマークコメント)

「あの人に答えてほしい」「この質問はあの人が答えられそう」というときに、回答リクエストを送ってみてましょう。

これ以上回答リクエストを送信することはできません。制限について

回答リクエストを送信したユーザーはいません