Roger
asked on
Automated positioning of UserForm before UserForm.Show
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:
With thisFrm
.StartUpPosition = 0
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width)
.top = Application.top + (0.5 * Application.height) - (0.5 * .height)
.Show
End With
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 call1()
Call userForm_Position("thisFrm ")
end sub
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 **
Next
Debug.print "thisFrm.name = "; thisFrm.name **
MsgBox "WEEE"
With thisFrm **
.StartUpPosition = 0 **
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width) **
.top = Application.top + (0.5 * Application.height) - (0.5 * .height) **
.Show **
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?
Floundering here!
Thanks
Kelvin
The following code places user form 'thisFrm' over the Application window:
With thisFrm
.StartUpPosition = 0
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width)
.top = Application.top + (0.5 * Application.height) - (0.5 * .height)
.Show
End With
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 call1()
Call userForm_Position("thisFrm
end sub
Sub userForm_Position(formName
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 **
Next
Debug.print "thisFrm.name = "; thisFrm.name **
MsgBox "WEEE"
With thisFrm **
.StartUpPosition = 0 **
.left = Application.left + (0.5 * Application.Width) - (0.5 * .Width) **
.top = Application.top + (0.5 * Application.height) - (0.5 * .height) **
.Show **
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?
Floundering here!
Thanks
Kelvin
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Rgonzo & Rory
Your comments address my problem.
I'll work on your solutions right now.
Many thanks!
Kelvin
Your comments address my problem.
I'll work on your solutions right now.
Many thanks!
Kelvin
ASKER
Many thanks for immediate responses which made several points. I have both solutions up and running.
Best regards
Kelvin
Best regards
Kelvin
it get to Wee because at
For Each frm In VBA.UserForms
it probably doesn't find anything and continues after the next
Regards