John Sp
John Sp

Reputation: 76

How to create a pop up input box in VBA for Excel and save the value in a variable?

I want to create a pop up box in VBA, so I take the input from the user and then I use it in my code.

The only "pop up" box I know at the moment is something like this:

MsgBox "This is a pop up box!"

It is a bit confusing for someone working only with C#.

How can I achieve my objective?

Upvotes: 2

Views: 21692

Answers (2)

Mathieu Guindon
Mathieu Guindon

Reputation: 71187

It is a bit confusing for someone working only with C#.

Indeed it is, since in C# the framework is nicely packaged in clear namespaces.

VBA doesn't have namespaces, but you can make your code not look like it's pulling global functions out of the sky by fully qualifying the global function calls you make.

The global MsgBox function, for example, lives in the VBA.Interaction module (as does the InputBox function); VBA.Conversion defines type-conversion functions such as CLng; VBA.DateTime exposes [almost] everything you need to work with dates and times...

Everything that's global is defined somewhere, and you can fully qualify any call to any global function.

You can explore what's defined in what referenced library, by bringing up the object browser (F2).

Upvotes: 1

Xabier
Xabier

Reputation: 7735

A simple Inputbox can be generated as below, this will ask the user to enter something and then display a messagebox with the contents of the variable:

Sub test()
    x = InputBox("Enter something", "Title")
    MsgBox x
End Sub

Upvotes: 2

Related Questions