Return to VBA Code Examples

VBA Input Statement

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

Input Description

Returns the open stream of an Input or Binary file (String).

Input Syntax

Input(Number, [#]FileNumber)

The Input statement contains 2 arguments:

Number: The number of characters to return.

FileNumber: Valid file number.

Examples of Excel VBA Input Statement

To test the Input statement, create a text file “test.txt” on the D drive.(D:\test.txt) Assume that the content of the file is as following.

abc
1 2 3
xy z

Please run the following code.

Sub Input_Fx_Example()
    Dim strContent As String
    Dim MyChar
    Open "D:\test.txt" For Input As #1    ' Open file.
    Do While Not EOF(1)    ' Loop until end of file.
        MyChar = Input(1, #1)    ' Get one character.
        strContent = strContent & MyChar '
    Loop
    MsgBox strContent
    Close #1    ' Close file.
End Sub

Then, the result will be as following.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as


Learn More!
vba-free-addin

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples