I use an extension monitor, and my userForms sometime appear in odd places on the screens.
The following code places user form 'thisFrm' over the Application window:
.StartUpPosition = 0
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width)
.top = Application.top + (0.5 * Application.height) - (0.5 * .height)
I tried to automate the positions of several forms, and ran into problems below...
The line: Debug.print "thisFrm.name = "; thisFrm.name gave an Error. I find thisFrm IS Nothing
When the lines (below) followed by '**' were commented out, no errors occurred, and MsgBox "WEEE" displayed (so the sub was run).
Sub userForm_Position(formName As String)
Dim frm As Object
Dim thisFrm As Object
For Each frm In VBA.UserForms
If frm.name = formName Then **
Set thisFrm = frm **
exit sub **
End If **
Debug.print "thisFrm.name = "; thisFrm.name **
With thisFrm **
.StartUpPosition = 0 **
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width) **
.top = Application.top + (0.5 * Application.height) - (0.5 * .height) **
End With **
Is the enumeration 'Each frm In VBA.UserForms' appropriate for forms that are not yet displayed ?
Ought the enumeration come from form objects specified in the VBE?