Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel file 'writeline' problem

Status
Not open for further replies.

julianbro

Programmer
Oct 5, 2003
1
GB
The following code open a text file for writting, none of the other sub's can 'see' the file handler.

I have named the 'file handler' = job

Public Sub make_job_file()
' create GEO_FILE
'Set fs = CreateObject("Scripting.FileSystemObject")
'Set job = fs.CreateTextFile("geo_job.job", True)
Dim fso, f1, job
Const ForWriting = 2
Set fso = CreateObject("Scripting.FileSystemObject")
fso.CreateTextFile ("geo_job.job")
Set f1 = fso.GetFile("geo_job.job")
Set job = f1.OpenAsTextStream(ForWriting, True)
End Sub

 
You mean you'd like to do

job.writeline "bla bla bla" from "everywhere"?

Haven't tried it, but you could try to declare it at module level (top of the module, below the option explicit)
dim job as textstream

this might be a bit dangerous, but just be sure to run your make_job_file routine before the 'job' can be invoked.

Either do that, or perhaps create a function which opens a file and appends whatever text you give it?

public function TextToFile(byval sText as string)
' open textfile, write to it close etc
end function

HTH Roy-Vidar
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top