2012-01-18 109 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/

顺便说一句,你可以跳过动画,直接进入下面的链接。你可能会觉得这部电影很有趣,但它所说的是“进度条=好,旋转的东西=坏”。

相关问题