Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003
    Location
    waterlooville, UK
    Posts
    3

    Unhappy Unanswered: write a line from Excel to a text file

    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"
    Some of the code has been left out to 'high light' my problem
    I have already opened a DATA I wish to convert
    The make or open new text file works. It does work in an other SUBrouteen


    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. #2
    Join Date
    Oct 2003
    Posts
    2

    Re: write a line from Excel to a text file

    Julian, the variable 'job' is DEFINITELY local to the routine where it is defined. Just take it out and define it at a module level i.e. outside of any subroutine

  3. #3
    Join Date
    Oct 2003
    Location
    waterlooville, UK
    Posts
    3

    Thumbs up Re: write a line from Excel to a text file

    This problem is now sorted.

    JB

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •