Return to VBA Code Examples

VBA Close Statement

Close Description

Concludes input/output (I/O) to a file opened by using the Open statement.

Close Syntax

Close [FileNumberList]

FileNumberList: [Optional] one or more file numbers that use the following syntax, where filenumber is any valid file number: [[ # ] filenumber ] [ , [ # ] filenumber ] . . .

Examples of Excel VBA Close Statement

Open "D:\test.txt" For Input As #1
    ' Read the file
Close
Open "D:\test.txt" For output As #1
    ' Write to the file
Close #1
Open "D:\test1.txt For Input As #1
Open "D:\test2.txt For Input As #2
    ' Read 2 files
Close #1, #2

 

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