View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Leith Ross[_332_] Leith Ross[_332_] is offline
external usenet poster
 
Posts: 1
Default Importing Text to Excel


Hello Aurbo,

Here is a macro that will open a text file and copy it line by line to
the active worksheet. Place this code in a VBA module to run it. You
didn't say if it was the first 10 lines of the file or not, but this is
the basic code to copy the text to the worksheet.

Calling the macro:
CopyTextToWorksheet ("Your file's name", "worksheet cell")

Sub CopyTextToWorksheet(ByVal FileToOpen As String, ByVal StartCell As
String)
Dim Data
Dim FF As Integer
Dim FN As String
Dim Row As Integer
Dim Rng As Range

FF = FreeFile
FN = FileToOpen
Set Rng = ActiveSheet.Range(StartCell)

Open FN For Input As #FF
Do While Not EOF(FF)
Input #FF, Data
Rng.Offset(Row, 0).Value = Data
Row = Row + 1
Loop
Close #FF
End Sub

Sincerely,
Leith Ross


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=488059