excelinputboxvba

Application.Inputbox [LEFT] and [TOP] not working in Excel Vba. Why?


I have a simple inputbox in my VBA code. I would like to set its starting position. I know the parameters [LEFT] and [TOP] should do that, but they won't work.

Here is what I have:

x = Application.InputBox(MyPrompt, MyTitle, , 50, 50)

and here is the function syntax

 InputBox(Prompt, Title, Default, Left, Top, HelpFile, HelpContextId, Type) 

(I left the third parameter [DEFAULT] blank).

No matter what numbers I use for LEFT and TOP, the inputbox always starts at the same place. What is wrong with that?


Solution

  • There's a difference between

    InputBox("prompt","title","default", 10000,10000) 
    

    which does use the top/left parameters, and

    Application.InputBox("prompt","title","default", 10000,10000)
    

    which doesn't.

    Note the top/left are in Points, so your provided values will need to be larger than you may be used to...

    http://msdn.microsoft.com/en-us/library/office/aa195768(v=office.11).aspx

    "The InputBox method differs from the InputBox function in that it allows selective validation of the user's input, and it can be used with Microsoft Excel objects, error values, and formulas. Note that Application.InputBox calls the InputBox method; InputBox with no object qualifier calls the InputBox function."