VBA to read data from TXT file

Here’s an example of VBA code that reads data from a TXT file and displays it in a message box:

Sub ReadDataFromTXT()
    Dim filePath As String
    Dim fileContent As String
    
    ' Specify the path of the TXT file
    filePath = "C:\Path\to\your\File.txt"
    
    ' Read the contents of the TXT file
    Open filePath For Input As #1
    fileContent = Input$(LOF(1), 1)
    Close #1
    
    ' Display the file content in a message box
    MsgBox fileContent
End Sub

In this code, you need to modify the filePath variable to the actual path of your TXT file.

When you run this code, it will open the TXT file specified by the filePath, read its contents, store it in the fileContent variable, and then display the file content in a message box.

Note: Make sure that the specified TXT file exists in the specified path and is accessible by the VBA code.

Pamai Tech
Turning ideas into Reality

Products

Office Add-in

Enterprise Solutions

Cloud Consulting

UI UX Design

Data Transformation

Services

FAQ's

Privacy Policy

Terms & Condition

Team

Contact Us

Company

About Us

Services

Features

Our Pricing

Latest News

© 2023 Pamai Tech