+ Reply to Thread
Results 1 to 5 of 5

Write string to text file and print?

  1. #1
    Ed
    Guest

    Write string to text file and print?

    A macro creates a string as its result. I'd like to create a text file,
    write the string to it, print the file, and dispose of the text file. I
    tried the FreeFile, Open, Write, and Print functions, but apparently I don't
    understand how to use them correctly. I got a file created, but there was
    nothing on it, Print didn't print it, and it saved itself with no file
    extension.

    Can someone point me in a good direction, please?

    Ed



  2. #2
    Tom Ogilvy
    Guest

    Re: Write string to text file and print?

    Actually you don't need to create a text file. You can write to the
    printer, same as writing to the file: the below prints several lines, but
    you should be able to adapt it to your situation.

    Sub Macro5()
    Dim ctrl as Long
    Dim tmpstr as String
    Open "LPT1:" For Output As #1
    Print #1, "[Start of Printing Test]"
    For ctrl = 1 To 10
    tmpstr = "Printing:" + Str(ctrl)
    Print #1, tmpstr
    Next
    tmpstr = "[End of printing test]" + Chr(12)
    Print #1, tmpstr
    Close #1
    End Sub


    To a Network printer


    First, I went to the immediate window in the VBE to query the activeprinter
    string


    ? activePrinter
    \\ARDAPS01\1D343E on Ne02:

    then I used the first part in the below code:

    Sub Macro5()
    Dim ctrl As Long
    Dim tmpstr As String
    Open "\\ARDAPS01\1D343E" For Output As #1
    Print #1, "[Start of Printing Test]"
    For ctrl = 1 To 10
    tmpstr = "Printing Line " + Str(ctrl)
    Print #1, tmpstr
    Next
    tmpstr = "[End of printing test]" + Chr(12)
    Print #1, tmpstr
    Close #1
    End Sub

    Worked for me.

    Regards,
    Tom Ogilvy


    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    news:[email protected]...
    > A macro creates a string as its result. I'd like to create a text file,
    > write the string to it, print the file, and dispose of the text file. I
    > tried the FreeFile, Open, Write, and Print functions, but apparently I

    don't
    > understand how to use them correctly. I got a file created, but there was
    > nothing on it, Print didn't print it, and it saved itself with no file
    > extension.
    >
    > Can someone point me in a good direction, please?
    >
    > Ed
    >
    >




  3. #3
    Ed
    Guest

    Re: Write string to text file and print?

    The LPT1 test worked great, Tom. Unfortunately, when I tried my string, the
    printer choked.

    The string is built through looping using
    strChanges = strChanges & str1 & " " & str3 & vbCr
    then
    strChanges = "Your changes are:" & vbCr & strChanges
    To print, I used
    Open "LPT1:" For Output As #1
    Print #1, strChanges
    Close #1

    I know at this point I have nine lines (I check with MsgBox). The printer,
    though, seems to want to overwrite everything onto the first line. Is this
    method not able to handle a multi-line string?

    Ed

    "Tom Ogilvy" <[email protected]> wrote in message
    news:%[email protected]...
    > Actually you don't need to create a text file. You can write to the
    > printer, same as writing to the file: the below prints several lines, but
    > you should be able to adapt it to your situation.
    >
    > Sub Macro5()
    > Dim ctrl as Long
    > Dim tmpstr as String
    > Open "LPT1:" For Output As #1
    > Print #1, "[Start of Printing Test]"
    > For ctrl = 1 To 10
    > tmpstr = "Printing:" + Str(ctrl)
    > Print #1, tmpstr
    > Next
    > tmpstr = "[End of printing test]" + Chr(12)
    > Print #1, tmpstr
    > Close #1
    > End Sub
    >
    >
    > To a Network printer
    >
    >
    > First, I went to the immediate window in the VBE to query the

    activeprinter
    > string
    >
    >
    > ? activePrinter
    > \\ARDAPS01\1D343E on Ne02:
    >
    > then I used the first part in the below code:
    >
    > Sub Macro5()
    > Dim ctrl As Long
    > Dim tmpstr As String
    > Open "\\ARDAPS01\1D343E" For Output As #1
    > Print #1, "[Start of Printing Test]"
    > For ctrl = 1 To 10
    > tmpstr = "Printing Line " + Str(ctrl)
    > Print #1, tmpstr
    > Next
    > tmpstr = "[End of printing test]" + Chr(12)
    > Print #1, tmpstr
    > Close #1
    > End Sub
    >
    > Worked for me.
    >
    > Regards,
    > Tom Ogilvy
    >
    >
    > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:[email protected]...
    > > A macro creates a string as its result. I'd like to create a text file,
    > > write the string to it, print the file, and dispose of the text file. I
    > > tried the FreeFile, Open, Write, and Print functions, but apparently I

    > don't
    > > understand how to use them correctly. I got a file created, but there

    was
    > > nothing on it, Print didn't print it, and it saved itself with no file
    > > extension.
    > >
    > > Can someone point me in a good direction, please?
    > >
    > > Ed
    > >
    > >

    >
    >




  4. #4
    Tom Ogilvy
    Guest

    Re: Write string to text file and print?

    for a printer you need to use vbCRLF, not just vbCr

    --
    Regards,
    Tom Ogilvy




    "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    news:[email protected]...
    > The LPT1 test worked great, Tom. Unfortunately, when I tried my string,

    the
    > printer choked.
    >
    > The string is built through looping using
    > strChanges = strChanges & str1 & " " & str3 & vbCr
    > then
    > strChanges = "Your changes are:" & vbCr & strChanges
    > To print, I used
    > Open "LPT1:" For Output As #1
    > Print #1, strChanges
    > Close #1
    >
    > I know at this point I have nine lines (I check with MsgBox). The

    printer,
    > though, seems to want to overwrite everything onto the first line. Is

    this
    > method not able to handle a multi-line string?
    >
    > Ed
    >
    > "Tom Ogilvy" <[email protected]> wrote in message
    > news:%[email protected]...
    > > Actually you don't need to create a text file. You can write to the
    > > printer, same as writing to the file: the below prints several lines,

    but
    > > you should be able to adapt it to your situation.
    > >
    > > Sub Macro5()
    > > Dim ctrl as Long
    > > Dim tmpstr as String
    > > Open "LPT1:" For Output As #1
    > > Print #1, "[Start of Printing Test]"
    > > For ctrl = 1 To 10
    > > tmpstr = "Printing:" + Str(ctrl)
    > > Print #1, tmpstr
    > > Next
    > > tmpstr = "[End of printing test]" + Chr(12)
    > > Print #1, tmpstr
    > > Close #1
    > > End Sub
    > >
    > >
    > > To a Network printer
    > >
    > >
    > > First, I went to the immediate window in the VBE to query the

    > activeprinter
    > > string
    > >
    > >
    > > ? activePrinter
    > > \\ARDAPS01\1D343E on Ne02:
    > >
    > > then I used the first part in the below code:
    > >
    > > Sub Macro5()
    > > Dim ctrl As Long
    > > Dim tmpstr As String
    > > Open "\\ARDAPS01\1D343E" For Output As #1
    > > Print #1, "[Start of Printing Test]"
    > > For ctrl = 1 To 10
    > > tmpstr = "Printing Line " + Str(ctrl)
    > > Print #1, tmpstr
    > > Next
    > > tmpstr = "[End of printing test]" + Chr(12)
    > > Print #1, tmpstr
    > > Close #1
    > > End Sub
    > >
    > > Worked for me.
    > >
    > > Regards,
    > > Tom Ogilvy
    > >
    > >
    > > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > > news:[email protected]...
    > > > A macro creates a string as its result. I'd like to create a text

    file,
    > > > write the string to it, print the file, and dispose of the text file.

    I
    > > > tried the FreeFile, Open, Write, and Print functions, but apparently I

    > > don't
    > > > understand how to use them correctly. I got a file created, but there

    > was
    > > > nothing on it, Print didn't print it, and it saved itself with no file
    > > > extension.
    > > >
    > > > Can someone point me in a good direction, please?
    > > >
    > > > Ed
    > > >
    > > >

    > >
    > >

    >
    >




  5. #5
    Ed
    Guest

    Re: Write string to text file and print?

    Ah!! Thank you!
    Ed

    "Tom Ogilvy" <[email protected]> wrote in message
    news:[email protected]...
    > for a printer you need to use vbCRLF, not just vbCr
    >
    > --
    > Regards,
    > Tom Ogilvy
    >
    >
    >
    >
    > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > news:[email protected]...
    > > The LPT1 test worked great, Tom. Unfortunately, when I tried my string,

    > the
    > > printer choked.
    > >
    > > The string is built through looping using
    > > strChanges = strChanges & str1 & " " & str3 & vbCr
    > > then
    > > strChanges = "Your changes are:" & vbCr & strChanges
    > > To print, I used
    > > Open "LPT1:" For Output As #1
    > > Print #1, strChanges
    > > Close #1
    > >
    > > I know at this point I have nine lines (I check with MsgBox). The

    > printer,
    > > though, seems to want to overwrite everything onto the first line. Is

    > this
    > > method not able to handle a multi-line string?
    > >
    > > Ed
    > >
    > > "Tom Ogilvy" <[email protected]> wrote in message
    > > news:%[email protected]...
    > > > Actually you don't need to create a text file. You can write to the
    > > > printer, same as writing to the file: the below prints several lines,

    > but
    > > > you should be able to adapt it to your situation.
    > > >
    > > > Sub Macro5()
    > > > Dim ctrl as Long
    > > > Dim tmpstr as String
    > > > Open "LPT1:" For Output As #1
    > > > Print #1, "[Start of Printing Test]"
    > > > For ctrl = 1 To 10
    > > > tmpstr = "Printing:" + Str(ctrl)
    > > > Print #1, tmpstr
    > > > Next
    > > > tmpstr = "[End of printing test]" + Chr(12)
    > > > Print #1, tmpstr
    > > > Close #1
    > > > End Sub
    > > >
    > > >
    > > > To a Network printer
    > > >
    > > >
    > > > First, I went to the immediate window in the VBE to query the

    > > activeprinter
    > > > string
    > > >
    > > >
    > > > ? activePrinter
    > > > \\ARDAPS01\1D343E on Ne02:
    > > >
    > > > then I used the first part in the below code:
    > > >
    > > > Sub Macro5()
    > > > Dim ctrl As Long
    > > > Dim tmpstr As String
    > > > Open "\\ARDAPS01\1D343E" For Output As #1
    > > > Print #1, "[Start of Printing Test]"
    > > > For ctrl = 1 To 10
    > > > tmpstr = "Printing Line " + Str(ctrl)
    > > > Print #1, tmpstr
    > > > Next
    > > > tmpstr = "[End of printing test]" + Chr(12)
    > > > Print #1, tmpstr
    > > > Close #1
    > > > End Sub
    > > >
    > > > Worked for me.
    > > >
    > > > Regards,
    > > > Tom Ogilvy
    > > >
    > > >
    > > > "Ed" <ed_millis@NO_SPAM.yahoo.com> wrote in message
    > > > news:[email protected]...
    > > > > A macro creates a string as its result. I'd like to create a text

    > file,
    > > > > write the string to it, print the file, and dispose of the text

    file.
    > I
    > > > > tried the FreeFile, Open, Write, and Print functions, but apparently

    I
    > > > don't
    > > > > understand how to use them correctly. I got a file created, but

    there
    > > was
    > > > > nothing on it, Print didn't print it, and it saved itself with no

    file
    > > > > extension.
    > > > >
    > > > > Can someone point me in a good direction, please?
    > > > >
    > > > > Ed
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1