Maximum length Prompt in Application.InputBox

R

RB Smissaert

Was caught out by the fact that the maximum length of the Prompt in
Application.InputBox is much less than in the
regular InputBox. The trouble was that the error you get is Runtime error
13: Type mismatch, so I was looking at the
datatypes of the different arguments, but the trouble is not with those.
The other trouble was that this seems to be mentioned nowhere.

It looks the maximum lenght of the Prompt with Application.InputBox is 256:

Sub test()

Dim i As Long
Dim lResult As Long
Dim strResult As String

On Error GoTo PAST1
For i = 245 To 400
SendKeys "{ENTER}", False
lResult = Application.InputBox(String(i, "x"), "title", 10, Type:=1)
Next

PAST1:
MsgBox i, , "maximum prompt length with Application.InputBox"
MsgBox i, , "maximum prompt length with Application.InputBox"

On Error GoTo PAST2
For i = 200 To 10000
SendKeys "{ENTER}", False
strResult = InputBox(String(i, "x"), "title", "a")
Next

PAST2:
MsgBox i, , "maximum prompt length with InputBox"
MsgBox i, , "maximum prompt length with InputBox"

End Sub


Haven't found the maximum yet with the regular InputBox, but it is much
more.

Is this is a known problem? I suppose it is.
Is there a workaround? I suppose not.


RBS
 
D

Dave Peterson

I don't ever recall using an inputbox to get a long string like that (even 255
characters).

Maybe designing a form and using a textbox would be a way around it.
 
D

Dave Peterson

And if you're really concerned about the length of the string returned, why use
application.inputbox at all.

You're probably not getting a number, formula, range, ....
 
D

Dave Peterson

It looks like the VBA inputbox is 254 characters.

Please ignore the previous message.
 
R

RB Smissaert

I am not talking about the return from the function, but the Prompt
argument.

RBS
 
D

Dave Peterson

Oh. Nevermind.

But there are limits to everything (well, almost).

If you do need a longer prompt, maybe a userform would be better.
 
R

RB Smissaert

I will just shorten the prompts.
I don't want to add more userforms as this add-in is big
enough already.
Maybe an option might be to put it in an VB6 ActiveX dll
or make a form on the fly.

RBS
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top