Anu
Anu

Reputation: 1129

How to center an input box in excel vba

Scenario

I have an input box by using the following code

total = Application.InputBox(prompt:="Please key in the total value", Title:="", Type:=2)

Problem

The input box is appearing randomly at the corners of the screen.

What I need

I need this input box align to the center of userform or the screen. Does anyone has any idea?

Upvotes: 3

Views: 6212

Answers (1)

Anu
Anu

Reputation: 1129

Above issue solved this way

total = Application.InputBox(prompt:="Please key in the total value", left:=(Application.Width / 2), top:=(Application.Height / 2), Title:="", Type:=2)

Gave left and top properties. It can be found by getting Application.width and Application.height. Dividing these values by 2 roughly move the inputbox to center regardless of screen size

Edit 1

I thought problem solved. But when I used different systems, it is not stable. So hopefully someone can help on this

Upvotes: 3

Related Questions