2012-01-18 112 views
2

是否有可能凍結的Excel,而我處理的東西嗎?我使用的2007年,我已經知道了張,凍結更新從VBA是可能的,但我正在尋找的整個事情有點凍結(與等待光標,也許一件好事,像昏暗的窗口或東西) 。我可以在處理某些東西時凍結Excel嗎?

有沒有人嘗試過這樣的事情從VBA?

回答

3

有沒有人嘗試過這樣的事情從VBA?

是。根據對我做任何我隱藏整個Excel應用程序或顯示與進度更新的一個窗體,以避免用戶干擾

例1(隱藏應用程序)

Option Explicit 

Sub Sample() 
    Application.Visible = False 

    '~~> Rest of the code 

    Application.Visible = True 
End Sub 

那種處理實施例2(使用其具有的「X」禁用用戶窗體)

創建一個用戶窗體和將此代碼有

Option Explicit 

Private Declare Function RemoveMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, _ 
ByVal wFlags As Long) As Long 

Private Declare Function GetSystemMenu Lib "user32" (ByVal hwnd As Long, ByVal bRevert As Long) As Long 

Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As String, _ 
ByVal lpWindowName As String) As Long 

Private Const MF_BYPOSITION = &H400& 

Private Sub UserForm_Initialize() 
    Dim lHwnd As Long 

    lHwnd = FindWindow("ThunderDFrame", "Please Wait...") 

    Do While lHwnd = 0 
     lHwnd = FindWindow("ThunderDFrame", "Please Wait...") 
     DoEvents 
    Loop 

    RemoveMenu GetSystemMenu(lHwnd, 0), 6, MF_BYPOSITION 
End Sub 

'~~> The below code will not be there 
'~~> This is just there so that if you try the above code then you can exit the form 
Private Sub UserForm_Click() 
    Unload Me 
End Sub 

和使用將是這樣

Option Explicit 

Sub Sample() 
    UserForm1.Show vbModeless 

    '~~> Rest of the code 

    Unload UserForm1 
End Sub 
+0

好球 - 請注意,另一個選擇是使用一個進度條(如[這一個](http://oreilly.com/pub/h/2607)) – JMax 2012-01-19 07:50:56

1

在加工過程中凍結Excel中設置screenupdating爲false。請務必在完成後將其設置爲true,否則用戶將無法與Excel進行交互。除了不與一堆運動嚇唬你的用戶,並在屏幕上閃爍,這將大大加快處理速度。

Sub Sample() 
    Application.ScreenUpdating = False 

    '~~> Rest of the code 

    Application.ScreenUpdating= True 
End Sub 

我同意JMax的進度條是一個不錯的選擇。你可以在這裏找到幾個不同的Excel VBA進度條:http://spreadsheetpage.com/index.php/blog/progress_bars_the_movie/

順便說一句,你可以跳過動畫,直接進入下面的鏈接。你可能會覺得這部電影很有趣,但它所說的是「進度條=好,旋轉的東西=壞」。

相關問題