Reputation: 1
I want to hide the excel file behind the Userform
.
Is it possible that when I move the Userform
with cursor, then Excel application behind the UserForm
also moves?
Upvotes: 0
Views: 924
Reputation: 19289
Extending the answer by @DougCoats - its important to set the Application.WindowState
to xlNormal
in order to manipulate Application
properties such as Top
and Left
etc. See the code below - you need to include a Module
and UserForm
in your workbook:
Option Explicit
Sub TestForm()
UserForm1.Show
End Sub
Option Explicit
Private Sub UserForm_Initialize()
HideApplicationBehindUserForm
End Sub
Private Sub UserForm_Layout()
HideApplicationBehindUserForm
End Sub
Private Sub HideApplicationBehindUserForm()
With Application
.WindowState = xlNormal
.Top = Me.Top
.Left = Me.Left
.Height = Me.Height
.Width = Me.Width
End With
End Sub
The Initialize
event will hide the Excel application behind the UserForm
when you open it. The Layout
event will move the application behind the UserForm
when you move the UserForm
around with your mouse. The code is the same in both circumstances - HideApplicationBehindUserForm
.
I see a little problem with my Excel where the application is slightly off to the border of the UserForm
:
Upvotes: 1
Reputation: 7117
The application has properties you can define
used like:
Application.Top = 0
Play around with this in various events in the userform until you find what youre after.
I strongly suggest learning how to capture the userform's values and then assigning them to the application.
Upvotes: 2