2015-06-30 186 views
1

當我運行下面的代碼時,爲什麼我的用戶窗體顯示「Not Responding」?我一直在試圖解決它,但尚未解決。宏運行時VBA userform是「Not Responding」

其實它有時會起作用。我認爲這個問題與屏幕更新有關。

enter image description here

' The input button in Sheet1 
Sub Rectangle1_Click() 

    'Remember time when macro starts 
    StartTime = Timer 

    ' To improve speed and performance 
    Application.ScreenUpdating = False 
    Application.EnableEvents = False 
    Application.Calculation = xlCalculationManual 

    ' Show the userform 
    UserForm1.Show vbModeless 
    UserForm1.Label1.Caption = "Calculation in progress ... " & vbNewLine & "Please be patient" 
    UserForm1.Label1.Font.Size = 12 
    UserForm1.Top = (Application.Height/2) - (UserForm1.Height/2) 
    UserForm1.Left = (Application.Width/2) - (UserForm1.Width/2) 
    UserForm1.CommandButton1.Visible = False 
    UserForm1.Repaint 

    Call Insert_RawData 

    'Determine how many seconds code took to run 
    SecondsElapsed = Round(Timer - StartTime, 2) 
    UserForm1.Label1.Caption = "This code ran successfully in " & SecondsElapsed & " seconds" 
    UserForm1.CommandButton1.Visible = True 

    ' Return back to the original settings 
    Application.ScreenUpdating = True 
    Application.EnableEvents = True 
    Application.Calculation = xlCalculationSemiautomatic 

End Sub 

回答

1

這可能是許多事情。如果問題像你提到的那樣是間歇性的,那麼很可能程序正在工作,而Windows只是將它標記爲不響應,因爲程序太難以響應操作系統了。

的可能的問題可能是一個,或它們的組合,以下的:

  • 工作簿中的(多個)開放通過Insert_RawData
  • 的數據量正在處理的數據量的宏時運行
  • Insert_RawData是它的工作原理與(不太可能)

一些SUG的一個細胞因壞/未處理值遇到錯誤gestions,試圖縮小源下來:

  • 如果有一致地運行,讓你得到了「不響應」,在Excel窗口,插入在調用一個破發點,以Insert_RawData然後看着它運行的方式看它是否擊中了錯誤
    • 或者,嘗試把一些錯誤檢查爲Insert_RawData和破發點上的代碼處理的錯誤校驗失敗
  • 的情況下捕捉處理的數據量(字節,細胞,無論是最簡單的)在e查看是否有一個門檻打擊(例如。 < = 1 GB運行良好,但> 1GB,應用程序看起來凍結)

除非你是在Insert_RawData打一個錯誤,雖然,它很可能是宏將完成,它只是可能需要很長一段時間。