Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 67
Default 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,


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,805
Default 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,


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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,

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merge data from an ascii file into a Word doc Bernie Excel Discussion (Misc queries) 1 September 6th 09 06:54 AM
using data from ascii file? NTaylor Excel Discussion (Misc queries) 2 December 21st 05 04:46 PM
Lookup & return data from ascii text file AH·C Excel Programming 0 November 26th 05 12:10 AM
Read data from ascii file Nazrul Excel Programming 2 October 23rd 03 08:21 PM
Selective read data from ascii file Steve Kim Excel Programming 0 August 20th 03 05:19 AM


All times are GMT +1. The time now is 04:39 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"