Help with textfile

Spurious

Active Member
Joined
Dec 14, 2010
Messages
439
Hello guys,

I got a question.

I got a text file in C:\test.txt
It's pretty big, now I want to take that textfile and everything that's in there and put it in one variable.

How do I do that?

Thanks for the help.
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Try:-
Care of Richard Schollar
Code:
[COLOR=navy]Sub[/COLOR] MG27May16
[COLOR=navy]Dim[/COLOR] Txt [COLOR=navy]As[/COLOR] [COLOR=navy]String,[/COLOR] Fpth [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
Fpth = "C:\Documents and Settings\test\Desktop\mick.txt"
Txt = ReadEntireTextFile(Fpth)
[COLOR=navy]End[/COLOR] [COLOR=navy]Sub[/COLOR]
 
Function ReadEntireTextFile(strFile [COLOR=navy]As[/COLOR] String) [COLOR=navy]As[/COLOR] [COLOR=navy]String[/COLOR]
[COLOR=navy]Dim[/COLOR] i [COLOR=navy]As[/COLOR] [COLOR=navy]Integer[/COLOR]
[COLOR=navy]If[/COLOR] Dir(strFile) <> "" [COLOR=navy]Then[/COLOR]
   i = FreeFile
   ReadEntireTextFile = Space(FileLen(strFile))
   Open strFile [COLOR=navy]For[/COLOR] Binary Access Read [COLOR=navy]As[/COLOR] #i
        Get #i, , ReadEntireTextFile
    Close #i
[COLOR=navy]Else[/COLOR]
    ReadEntireTextFile = "File not found!"
[COLOR=navy]End[/COLOR] If
[COLOR=navy]End[/COLOR] Function
Regards Mick
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,551
Messages
6,179,473
Members
452,915
Latest member
hannnahheileen

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