Page 1 of 3 123 LastLast
Results 1 to 15 of 32
  1. #1
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why won't this print ? (VB6)

    I have a list of word docs in a listbox, I was hoping to print using the following code:
    But it doesn't.
    I know printing in VB isn't straight forward, but the <font color=blue>Print</font color=blue> seemed to be available.


    <pre>Private Sub cmdPrint_Click()
    Dim fso As New Scripting.FileSystemObject
    Dim N As Integer
    Dim strPath As String

    strPath = "C:MM-Utilities"

    Set fso = New FileSystemObject
    For N = 0 To lstDocs.ListCount - 1
    If lstDocs.Selected(N) Then
    fso.Print strPath & lstDocs.List(N)
    End If
    Next N
    Set fso = Nothing
    End Sub</pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    As far as I know, Print is not a method of FileSystemObject. It wouldn't work this way anyway, for printing in Windows is page-oriented, not line-oriented (the way line printers and matrix printers were)

    You could use the TextStream object from the Scripting library, or the old-fashioned Basic instructions for text files (Open #, Print #, Close #), to create a text file containing the selected items, then print this file using ShellExecute.

  3. #3
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Yes I see Hans, pity though, you would have thought Microsoft would have included a print method in the FS-Object concidering it gives the programmer so many options with files.

    I managed another way, which works (I may add a print dialog later) .
    <pre>Private Sub cmdPrint_Click()
    Dim fso As New Scripting.FileSystemObject
    Dim N As Integer
    Dim strPath As String
    Dim oWord As Object
    Dim oDoc As Object

    strPath = "C:MM-Utilities"

    Set fso = New FileSystemObject
    For N = 0 To lstDocs.ListCount - 1
    If lstDocs.Selected(N) Then
    Set oWord = CreateObject("Word.Application")
    Set oDoc = oWord.Documents.Add(strPath & lstDocs.List(N))
    oWord.Visible = False
    oDoc.printout

    End If
    Next N
    Set fso = Nothing

    Set oWord = Nothing
    End Sub</pre>


    What do you think ?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    Umm, I had misread your question originally, so my previous reply is irrelevant. Sorry about that. (You could still use ShellExecute to print the docs, though)

    Warning: you are creating a new Word.Application object for each selected item in the list box. I would create one Word object before going into the loop, and open the documents instead of creating new ones from them. And you don't need fso any more.

    Code (with error handling - always recommended) attached.

  5. #5
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Hans
    The appologies lye here, I hadn't informed you that the docs were already created.

    Close though, I'm getting the error I had before creating the word application within the loop.
    I don't get the error if all is held within !!

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    Temporarily insert <code>oWord.Visible = True</code> below the line <code>Set oWord = ...</code>, and when the error message appears, activate Word (task bar or Alt+Tab) to find out what the dialog says.

    Depending on the nature of the message, it may or may not be safe to suppress it by inserting <code>oWord.DisplayAlerts = False</code> before, and <code>oWord.DisplayAlerts = False</code> after the loop. (This is the Word equivalent of DoCmd.SetWarnings in Access.)

  7. #7
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Ahhhhhhhhhh !!

    "oWord.DisplayAlerts = False " , Thats very interesting

    I'll try it and see,

    Thanks again Hans

    ************************************************** *****************
    Edited :::

    Should it be oWord.DisplayAlerts = False then set to True after the loop, or was your post correct in setting to False both before and after ?

    ************************************************** ******************

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    I would still investigate why the error occurs. Sometimes, it is OK to suppress error messages, but if you don't know what you are suppressing, ...

    Enter Sigmund Freud

  9. #9
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Hans

    I still can't trap down any serious errors other than a margin setting."Margins of section 1 outside of print area", which I've played about with for ages.
    All that does is convert the end doc into 3 pages, the middle being blank ?
    Also the end paragraph compresses at the end of the last page.

    Don't know if you can see anything, I've attached the raw docs incase you do !

  10. #10
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Why won't this print ? (VB6)

    Something to try if all else fails: If your systems have the Windows Script Host enabled, you could use the WshShell object's Execute method to simulate the Start>Run "command line." Then copy the command line (including startup switches) from Windows Explorer's File Types dialog for DOC>Print and plug in your file names.

  11. #11
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    Either your printer settings are different from mine, or you have changed the code to convert the invoices and estimates. On my system, the raw document you posted converts correctly (2 pages) with the code we discussed earlier.

  12. #12
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Hans

    1/ Do you get the "section 1 out of print range" ?, when you print ?

    2/ The attached png shows how the end paragraph compresses under the totals (Top = Converted), (Bottom = Original raw file)

    3/ If I alter the section length of the template, that's where the doc converts to 3 pages with the middle page blank !!

  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    1. No.

    2. Yes, that is the way the conversion is written. The raw file contains lots of empty paragraphs. To fit the documents into the template with its header, I remove all empty lines.

    3. Don't.

  14. #14
    Silver Lounger
    Join Date
    Jun 2002
    Location
    Cheadle, Staffordshire
    Posts
    2,177
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Why won't this print ? (VB6)

    Hans

    1/ If you're not getting the error, do I need to look at any printer settings or something ?

    2/ Ok , yes I understand how the code manipulates the empty paragraphs, is it worth adding one single empty line, sort of a Vbcrlf effect.

    3/ Ok I won't ! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  15. #15
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Why won't this print ? (VB6)

    Perhaps you can zip and attach one of the documents that cause the error (that is, the processed document, not the raw document)?

Page 1 of 3 123 LastLast

Posting Permissions

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