Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default opening and write to a text file in excel

This one I can't get over.

I open a file using "job" as my file handler, but no
other 'sub' can see the
file handler.
The debugger stops with the error "object required"


Public Sub make_job_file()
' create GEO_FILE
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

Sub jobname()
job_name = InputBox("input Job Name", "Job Name",
job_name, 100, 1)
job.WriteLine "51=" + job_name
Job_date = InputBox("input correct date", "Job Date",
Job_date, 100, 1)
job.WriteLine "51=" + Job_date
End Sub

Sub station()
job.WriteLine "2=" + Cells(row, B) ' AT STATION
job.WriteLine "3=" + Cells(row, H) ' INSTRUMENT HEIGHT
job.WriteLine "21=0.0000" ' DUMMY RO ANGLE NOT
USED
End Sub

Can you spot where I have gone wrong.
Please don't tell me one sub routine can't see another
subroutine's
variables.

Julian B

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default opening and write to a text file in excel

OK, I won't tell you one routine can't see another routine's variables.
I'll type it at you and you can read it.

To get around this, delcare your variables in the Declarations section. All
you have to do is move the declaration to outside the subroutines, before
the first one:

Dim fso, f1, job
Public Sub make_job_file()
' create GEO_FILE
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

and so on.

"julian brotherton" wrote in message
...
This one I can't get over.

I open a file using "job" as my file handler, but no
other 'sub' can see the
file handler.
The debugger stops with the error "object required"


Public Sub make_job_file()
' create GEO_FILE
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

Sub jobname()
job_name = InputBox("input Job Name", "Job Name",
job_name, 100, 1)
job.WriteLine "51=" + job_name
Job_date = InputBox("input correct date", "Job Date",
Job_date, 100, 1)
job.WriteLine "51=" + Job_date
End Sub

Sub station()
job.WriteLine "2=" + Cells(row, B) ' AT STATION
job.WriteLine "3=" + Cells(row, H) ' INSTRUMENT HEIGHT
job.WriteLine "21=0.0000" ' DUMMY RO ANGLE NOT
USED
End Sub

Can you spot where I have gone wrong.
Please don't tell me one sub routine can't see another
subroutine's
variables.

Julian B



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Default settings when opening a text file with Excel David Fitzwater Excel Discussion (Misc queries) 1 August 12th 08 08:07 PM
How do I prevent a text to columns while opening a csv file in Excel Michiel via OfficeKB.com Excel Discussion (Misc queries) 3 July 28th 08 01:30 PM
opening text file in excel problem jz193 Excel Discussion (Misc queries) 18 February 10th 06 02:42 PM
Opening a text file in excel Opyuse Excel Discussion (Misc queries) 4 June 13th 05 09:23 PM
write a line from Excel to a text file julian_bro Excel Programming 1 September 30th 03 01:29 AM


All times are GMT +1. The time now is 01:48 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"