×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Excel VBA User Form Centering when using two Monitors

Excel VBA User Form Centering when using two Monitors

Excel VBA User Form Centering when using two Monitors

(OP)
Hi

Can anyone help with the following. I have a User Form which I would like to centre (on opening) on one of my two monitors.

I have found the following code (which runs on user form initialising)

Private Sub UserForm_Initialize()
With GenAvailInputForm
Me.StartUpPosition = 0
Me.Left = Application.Left + (0.5 * Application.Width) - (0.5 * .Width)
Me.Top = Application.Top + (0.5 * Application.Height) - (0.5 * .Height)
Me.Show
End With
End Sub

It seems to work but when I close the form on the disable button I get the following message

Run-Time error '91'

Object Variable or With Block Variable not set

I'm a bit of a novice so any help would be appreciated

Thanks

RE: Excel VBA User Form Centering when using two Monitors

>but when I close the form on the disable button I get the following message

Ok, but the code you've shown us is simply for the form initialising, not closing. We need to see the code that runs when you are clicking the 'disable' button.

RE: Excel VBA User Form Centering when using two Monitors

Eliminate Me.Show line of code.


---- Andy

There is a great need for a sarcasm font.

RE: Excel VBA User Form Centering when using two Monitors

(OP)
Hi Strongm and Andrzejek. Removing the Me.Show line code worked

Many Thanks

Paul

RE: Excel VBA User Form Centering when using two Monitors

Good catch - although I'm not quite sure how the rest of the code is supposed to work, since I'm pretty sure the Access Application object doesn't have Left, Top, Width or Height properties - which tends to make me think this code is actually in Excel (or possibly Word), in which case, apart from the Me.Show it is fine. Only we don't actually appear to need With or End With statements ; I presume they are an artifact of some earlier version of the code ...

RE: Excel VBA User Form Centering when using two Monitors

(OP)
strongm - apologies as I may have misled you. This is in Excel so maybe I am in the wrong Forum?

RE: Excel VBA User Form Centering when using two Monitors

(OP)
Many thanks strongm. I'll be more vigilant regarding the Forum I am joining in future

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close