Function to get first line of specified text files

vulture49

New Member
Joined
Jun 1, 2015
Messages
4
Hi,

I'm looking for a FUNCTION for my task as described below:

- I have numerous text files, and all their filenames/path are in column A
- I want column B to return the first line of the text file (its counterpart in column A), by using a function like =FirstLine(A2)

Is this possible? Thanks! Hoping someone could help me out. Been searching everywhere for this. All I see suggests that I import the text file into excel, which is out of the question, because these te t files are really plenty.
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
try this
VBA Code:
Function GetFirstLine(MyFile As String) As String
    If Dir(MyFile) <> "" Then
        Open MyFile For Input As #1
            Line Input #1, GetFirstLine
        Close
    End If
End Function
 
Upvote 0
try this
VBA Code:
Function GetFirstLine(MyFile As String) As String
    If Dir(MyFile) <> "" Then
        Open MyFile For Input As #1
            Line Input #1, GetFirstLine
        Close
    End If
End Function
Hey! This worked as intended!! Thank you so so so much!! It works like a gem. More power to you!!!
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,204
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top