Macro to Import and Export Text files into Excel


Export data (Write) from a Worksheet to a Text File


Sub WriteToTextFile()
Open "E:\XLnCAD.txt" For Output As 1
Range("D5").Select
Do Until ActiveCell.Value = ""
Print #1, ActiveCell.Value
ActiveCell.Offset(1, 0).Select
Loop
Close (1)
End Sub

Import data (Read) from a Text File to a Worksheet


Sub readfromtextfile()
Dim temptext As String
Open "E:\XLnCAD.txt" For Input As 2
Range("I6").Select
Do Until EOF(2)
Input #2, temptext
ActiveCell.Value = temptext
ActiveCell.Offset(1, 0).Select
Loop
Close (2)
End Sub

Leave a Reply

Your email address will not be published.Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.