ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Importing Text to Excel (https://www.excelbanter.com/excel-programming/346555-importing-text-excel.html)

Aurbo

Importing Text to Excel
 

Greetings,

I have to figure out a way to import only 10 lines of text from a text
file.

Any suggestions?

Cheers
Aurbo


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


Leith Ross[_332_]

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


nsv[_9_]

Importing Text to Excel
 

You put your question in the programming forum, but just in case you
need to do it only once, here is a procedu
File-Open (or CTRL+O)
Files of Type to be Text-files
select if you have a delimiter or if you will just have each line in
one cell.

NSV


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



All times are GMT +1. The time now is 11:35 AM.

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