ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   A Macro that gets data from an ASCII file (https://www.excelbanter.com/excel-programming/419364-macro-gets-data-ascii-file.html)

Boris

A Macro that gets data from an ASCII file
 
All,

I would like to write a Macro that does the following:

1. Opens an ASCII file (e.g. a *.txt or *.raw file)
2. Copies the data from the ASCII file into the Excel file.
Every line from the ASCII line should be inserted into a new row
3. closes the file

Could someone tell me how to do this?

Best,



Sheeloo[_3_]

A Macro that gets data from an ASCII file
 
Go to TOOLS|Macro
Start recording a macro
Choose name

Choode File|Open
Select your file
Make your choices in the import wizard

Stop recording your macro

Tools|Macro|Macros
Select your macro and click EDIT

You have your macro
Now you can adapt it

"Boris" wrote:

All,

I would like to write a Macro that does the following:

1. Opens an ASCII file (e.g. a *.txt or *.raw file)
2. Copies the data from the ASCII file into the Excel file.
Every line from the ASCII line should be inserted into a new row
3. closes the file

Could someone tell me how to do this?

Best,



Chip Pearson

A Macro that gets data from an ASCII file
 
Try some code like the following:

Sub AAA()
Dim FName As Variant
Dim FNum As Integer
Dim LineRead As String
Dim R As Range
Set R = ActiveSheet.Range("A1") '<<< CHANGE START CELL
FName = Application.GetOpenFilename( _
"Text Files (*.txt;*.raw),*.txt;*.raw")
If FName = False Then
' no file selected
Exit Sub
End If
FNum = FreeFile()
Open FName For Input Access Read As #FNum
Do Until EOF(FNum)
Line Input #FNum, LineRead
R.Value = LineRead
Set R = R(2, 1)
Loop
Close #FNum
End Sub




Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)


On Fri, 31 Oct 2008 08:45:00 -0700, Boris
wrote:

All,

I would like to write a Macro that does the following:

1. Opens an ASCII file (e.g. a *.txt or *.raw file)
2. Copies the data from the ASCII file into the Excel file.
Every line from the ASCII line should be inserted into a new row
3. closes the file

Could someone tell me how to do this?

Best,



All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com