Thank you for your helpful suggestions. I have since tested with other PCs and found that this problem occurs only on one particular PC. So it must be some error on the side of the PC, not the code itself.
For reference, here is the script I have written. (This is only the essence. Error handling, etc. are omitted)
Assuming a UserForm1 is created:
Public Declare PtrSafe 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
Public Const HWND_TOPMOST = -1
Public Const HWND_NOTOPMOST = -2
Public Const SWP_NOMOVE = &H2
Public Const SWP_NOSIZE = &H1
Public Declare PtrSafe Function FindWindow Lib "User32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Sub ShowFormOnTop()
Dim bwind As Long
Load UserForm1
UserForm1.Show vbModeless
If UserForm1.Visible = True Then
bwind = FindWindow(vbNullString, UserForm1.Caption)
Else
bwind = 0
End If
SetWindowPos bwind, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE Or SWP_NOSIZE
End Sub
----------------------------
Thank you again.
Bookmarks