Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any command equivalent to readline in vba?

Is there a command equivalent to readLine of Java in VBA. I want to use the text input in the immediate window and put it in a variable. Is it possible?

like image 473
Emi Avatar asked Mar 14 '23 14:03

Emi


1 Answers

You can't use the Immediate Window interactively. For one thing -- while a sub is running it won't accept any keyboard input. You can, however, use it to pass data to a sub or function when you invoke it, so in a sense you can "scrape" data that is there already. Something along these lines:

Sub AddNums(ParamArray nums())
    Dim total As Double
    Dim i As Long
    For i = 0 To UBound(nums)
        total = total + nums(i)
    Next i
    Debug.Print total
End Sub

For example:

enter image description here

Beyond that -- you could move the input-gathering phase to a VBScript script running in console mode, invoke it from VBA, and use either a file (which the script writes to) or perhaps the clipboard to get the data from the script after it is done running. This should be feasible, though it is probably better to find a more idiomatic (form-based) way to do it within VBA.

like image 189
John Coleman Avatar answered Mar 26 '23 06:03

John Coleman