Userform BringToFront

NateGreen

New Member
Joined
Mar 7, 2014
Messages
3
Issue: Bring to front userform when Excel is invisible

Background info:
I am launching a vbs script from AutoCAD which, in turn, opens a particular excel workbook and initiate a macro. This workbook is opened invisibly (i.e. "xlApp.Visible = False", "Application.Visible = False"), so that the end user is can only view the userforms created by the macro. The problem that I'm running into is that the userforms are being displayed behind AutoCAD (or any other active window). I want to force these forms to appear on top of other windows.
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Yhis can be done using 2 API calls - one to get the window handle (which changes each time it is opened) and the other to bring the window to the top.
Code:
'==============================================================
'- CODE TO BRING USERFORM WINDOWTO THE TOP
'==============================================================
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function BringWindowToTop Lib "user32" (ByVal Hwnd As Long) As Long
Dim Hwnd As Long
'-------------------------------------------------------------

Private Sub UserForm_Initialize()
    Hwnd = FindWindow("ThunderDFrame", Me.Caption)
    BringWindowToTop (Hwnd)
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,839
Messages
6,121,891
Members
449,058
Latest member
Guy Boot

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top