InputBox default value as prefix

tommy03

Board Regular
Joined
Jun 8, 2004
Messages
131
I could swear that I read how to do this here, but my search for it came up empty - so here goes.

I have an InputBox that provides a default value ("A") :

NewFile = InputBox("Enter File Number", "File Creation", "A")

however, the default value is actually a prefix for a longer file name (consisting of numbers - such as "A123456789").

when the InputBox is called, the default value appears, and it is necessary to arrow-over to continue entering the file name.
Is there a way to have the curser set after the "A" (to the end), so that the user only needs to type the remaing name of the file?

maybe it's more work than it's worth (in this case - since it's only 1 character), but it would be good to know how to do this in cases where a longer default prefix might be needed.

anyone have the solution to this ?

thanks
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
How about if you add the prefix after the entry? So say they enter 123456789, and the code adds the A in front of it. For example:

Sub test()
NewFile = "A" & InputBox("Enter File Number", "File Creation")
MsgBox NewFile
End Sub
 
Upvote 0
very clever approach (I should have come up with that first thing :oops: )

but let's just say (for the heck of it - and because I really do believe that I saw it somewhere on this forum) that I wanted to have the curser at the end of the field.
(hmmmm.... maybe the solution that I remember seeing was for a textbox on a userform :confused: Would that matter? hmmmm.... maybe so. Not sure though).
if anyone remembers that, I'd appreciate a reference to it.

in the meantime, I'll happily use your solution HOTPEPPER.
thanks :biggrin:
 
Upvote 0
Sub myMsg()
Dim Message, Title, Default, MyValue
Message = "Enter a ""Test""" ' Set prompt.
Title = "Run a Test!" ' Set title.
' Set default.
Default = "Test1"

'Set InputBox Default to "Un-selected!"
SendKeys "{Right}"

' Display message, title, and default value.
MyValue = InputBox(Message, Title, Default)

MsgBox MyValue
End Sub
 
Upvote 0
This is the only way I know to get the "Default" displayed un-selected and at the ready prompt. It works by stacking commands: The send keys stacked with the InputBox's return value.

All the Default cancantanations with "vbKeyRight" or SendKeys "{Right}" fail.

So using the SendKeys command just before the InputBox return value is the best way I have found.
 
Upvote 0

Forum statistics

Threads
1,215,040
Messages
6,122,806
Members
449,095
Latest member
m_smith_solihull

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top