CubaRJ
New Member
- Joined
- Mar 21, 2022
- Messages
- 29
- Office Version
- 365
- 2019
- Platform
- Windows
Hi, I am trying to improve the form open events to be placed in the middle of the active screen, but I noticed I have to repeated it thru all Initialize event of each form.
This is the code I am using to call a function to calculate the window sizing:
Notice the "Me" is the part I am willing to make a global variable carrying the name of the userform so I won´t have this piece pasted all over the Initialize event and have just a generic call from them.
I found thise code tha makes the Userform a variable, but it does not work as strFormName does not pass to the function to calculate the screen...
Can anyone helpe me?
This is the code I am using to call a function to calculate the window sizing:
VBA Code:
Private Sub UserForm_Initialize()
Dim sngLeft As Single, sngTop As Single
Call ReturnPosition_CenterScreen(Me.Height, Me.Width, sngLeft, sngTop): Me.Left = sngLeft: Me.Top = sngTop
End Sub
Notice the "Me" is the part I am willing to make a global variable carrying the name of the userform so I won´t have this piece pasted all over the Initialize event and have just a generic call from them.
I found thise code tha makes the Userform a variable, but it does not work as strFormName does not pass to the function to calculate the screen...
VBA Code:
Public Sub OpenForm(strFormName As String)
'Code to open subforms using a variable so we can use the positioning code only once instead of writing in every form open event.
VBA.UserForms.Add(strFormName).Show
End Sub
Sub FormForecast()
Call OpenForm("frmForecastCrewChanges")
End Sub
Can anyone helpe me?