加载工作簿时,我有一个用于“冒泡”模仿的代码。我试图使它们出现在Workbook_open上,但是出了点问题,我的代码无法正常工作。点未运行。我认为当前代码中的问题在于Application.OnTime Now + TimeValue("00:00:01")
来自Excel Userform animated dots on loading
的代码如果仅通过.Show
命令单独运行UserForm,则一切正常。
这是我的UserForm代码:
Private Sub UserForm_Initialize()
Dim AppXCenter, AppYCenter As Long
Dim bytOpacity As Byte
bytOpacity = 192 ' variable keeping opacity setting
hWnd = FindWindow("ThunderDFrame", Me.Caption)
Call SetWindowLong(Me.hWnd, GWL_EXSTYLE, GetWindowLong(Me.hWnd, GWL_EXSTYLE) Or WS_EX_LAYERED)
Call SetLayeredWindowAttributes(Me.hWnd, 0, bytOpacity, LWA_ALPHA)
AppXCenter = Application.Left + (Application.Width / 2)
AppYCenter = Application.Top + (Application.Height / 2)
With Me
.StartUpPosition = 0
.Top = AppYCenter - (Me.Height / 2)
.Left = AppXCenter - (Me.Width / 2)
End With
HideTitleBar.HideTitleBar Me
Application.OnTime Now + TimeValue("00:00:01"), "loadingdots"
End Sub
加载点:
Public Sub loadingdots()
If IsLoaded("Loading") = True Then
If Len(Loading.Label2.Caption) = 10 Then
Loading.Label2.Caption = "."
Else
Loading.Label2.Caption = Loading.Label2.Caption & "."
End If
Application.OnTime Now + TimeValue("00:00:01"), "loadingdots"
End If
End Sub
检查是否已加载:
Public Function IsLoaded(form As String) As Boolean
Dim frm As Object
For Each frm In VBA.UserForms
If frm.Name = form Then
IsLoaded = True
Exit Function
End If
Next frm
IsLoaded = False
End Function