2
Good afternoon,
I am creating a Dashboard in which when running Excel a userform is opened, maximized and Excel is hidden. My code works perfectly for a PC with only one monitor.
When using a PC with two monitors the VBA opens the userform on the main monitor, but to maximize it takes the information from the monitor on which Excel was open.
Someone knows how to make the VBA identify on which monitor Excel is open and open the userform on that monitor?
'Set the Windows style so that the userform has a minimise and maximise button
lngCurrentStyle = GetWindowLong(lngHWnd, GWL_STYLE)
lngNewStyle = lngCurrentStyle Or WS_MINIMIZEBOX 'Or WS_MAXIMIZEBOX
lngNewStyle = lngNewStyle And Not WS_VISIBLE And Not WS_POPUP 'And WS_MINIMIZEBOX
SetWindowLong lngHWnd, GWL_STYLE, lngNewStyle
'Set the extended style to provide a taskbar icon
lngCurrentStyle = GetWindowLong(lngHWnd, GWL_EXSTYLE)
lngNewStyle = lngCurrentStyle Or WS_EX_APPWINDOW
SetWindowLong lngHWnd, GWL_EXSTYLE, lngNewStyle
ShowWindow lngHWnd, SW_SHOW
'Remove a barra superior
HideTitleBar Me
'Maximiza o formulário
With Me
.StartUpPosition = 1
.Width = Application.Width
.Height = Application.Height
.Left = 0
.Top = 0
End With
NOTE: I will not post the complete code here because it is not a very complex code, however, long.
Thank you all.
Thanks friend, I had just modified this in my code after reading something similar in another forum, but it is not yet ideal. Ideally the program would see that it has two monitors and ask on which one it should be opened. Would it have as?
– Thiago Andrade
I found a way to perform without GPU, but in mine the test did not work. Because the presence of the video card alters the programming of the monitors. Then the most indicated would be to open in the same Excel application. For more advanced Guis, I suggest abandoning the VBA and go to other programming languages.
– danieltakeshi
Unfortunately I can’t abandon excel.
– Thiago Andrade