我不認爲有任何內置的方式,使在VBA頂部的形式入住,但一個問題是,你調用DoEvents當你在表單上更新什麼?我的經驗是,除非您在循環中敲入Next語句之前調用DoEvents,否則表單不會重新繪製。
如果這不是你的問題,你可以使用Windows API調用來把一個窗口的頂部,雖然我不知道它使用此代碼停留在頂部:
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Const SWP_NOMOVE = 2
Const SWP_NOSIZE As Long = 1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Private Declare Function SetWindowPos Lib "user32" _
(ByVal hwnd As Long, _
ByVal hWndInsertAfter As Long, _
ByVal x As Long, _
ByVal y As Long, _
ByVal cx As Long, _
ByVal cy As Long, _
ByVal wFlags As Long) As Long
Private Function SetTopMostWindow(hwnd As Long, Topmost As Boolean) As Long
If Topmost = True Then 'Make the window topmost
SetTopMostWindow = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS)
Else
SetTopMostWindow = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS)
SetTopMostWindow = False
End If
End Function
Private Function GetFormHwnd() As Long
GetFormHwnd = FindWindow(CLng(0), Me.Caption)
End Function
Public Sub SetFormAsTopMostWindow()
Call SetTopMostWindow(GetFormHwnd(), True)
End Sub
我把這個一個表單的代碼模塊,它在移動其他應用程序時似乎可以工作;它保持在頂部。
謝謝,將有一個發揮。 – user51498 2009-02-02 20:38:46