Vba (1 Viewer)

flaghippo

Registered User.
Local time
Yesterday, 22:53
Joined
Jan 22, 2012
Messages
19
Hi All
I am reading a text file (.txt) into VBA (ACCESS)
The text file could have an unknown number of lines.
I need to write all the lines into one variable for use as an email line.
Can any one help ?????
 

vbaInet

AWF VIP
Local time
Today, 06:53
Joined
Jan 22, 2010
Messages
26,374
You can use one of the following methods:
Code:
    Dim fso As FileSystemObject
    Dim strContents As String

    Set fso = New FileSystemObject
    strContents = fso.OpenTextFile("[COLOR=Red]... Path to file here ...[/COLOR]", ForReading).ReadAll
Code:
    Dim intFileNum As Long
    Dim strContents As String
    
    intFileNum = FreeFile
    Open "[COLOR=Red]... Path to file here ...[/COLOR]" For Input As intFileNum
        strContents = Input(LOF(intFileNum), intFileNum)
    Close intFileNum
strContents will contain the contents of your file.
 

flaghippo

Registered User.
Local time
Yesterday, 22:53
Joined
Jan 22, 2012
Messages
19
Hi
That work great but I need to have all the lines in the text file in one continuous
line without carriage returns.
Thanks
Mike
 

DJkarl

Registered User.
Local time
Today, 00:53
Joined
Mar 16, 2007
Messages
1,028
strContents = replace(strContents ,vbCr,"")

or perhaps

strContents = replace(strContents ,vbCrLf,"")
if you have line feeds as well
 

Users who are viewing this thread

Top Bottom