在我处理某些事情时,是否可以冻结Excel



在处理某些内容时,是否可以冻结Excel?我使用的是2007。我已经知道冻结VBA中的图纸更新是可能的,但我正在寻找整个事情的一个小冻结(使用等待光标,也许还有一些好的东西,比如变暗窗口或其他什么)。

有人从VBA中尝试过这样的东西吗?

有人从VBA中尝试过这样的东西吗?

是的。根据我正在做的处理类型,我要么隐藏整个Excel应用程序,要么显示带有进度更新的用户表单,以避免任何用户干扰

示例1(隐藏应用程序)

Option Explicit
Sub Sample()
    Application.Visible = False
    '~~> Rest of the code
    Application.Visible = True
End Sub

示例2(使用禁用了"X"的Userform)

创建一个用户表单并将此代码放置在中

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

要在处理过程中冻结Excel,请将屏幕更新设置为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/

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

最新更新