Home > Software design >  Object required when retrieving value from InputBox
Object required when retrieving value from InputBox

Time:11-04

Hey guys I have a a coding issue in vba.

 Dim table As String
 Set table = InputBox("Text","Title","Default")

I then get the message:

Error while compiling Object required

The phrase

    table =

Is marked blue

Why do I get the error while compiling?

CodePudding user response:

If InputBox does return a String you have to remove the Set (which is only needed for objects):

Dim table As String
table = InputBox("Text","Title","Default")

CodePudding user response:

The Set statement is used with variables that are an Object type.

Per the VBE Glossary for object-type;

A type of object exposed by an application through Automation, for example, Application, File, Range, and Sheet. Use the Object Browser or refer to the application's documentation for a complete listing of available objects.

A String is not an object data type so you don't need to include the Set keyword.

  • Related