Results 1 to 10 of 10

Thread: How do I send a *file*(txt + graphics) to printer?

  1. #1

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    How do I send a *file*(txt + graphics) to printer?

    What I've done is set up Adobe's PDFWriter as my default printer so that all I can quick-create PDFs . I do this by opening the file in WordPad and using the standard File>Print and it does the rest.

    What I'm trying to do with VB is find [some sort of standard API maybe?] that can accept a string variable perhaps which contains the path and name of a file. I'm hoping that this API or Function or anything can then just send that file to the default printer and let it (the printer) deal with it. I would normally use the Printer object but the files will be .doc and contain a graphical header (of varying size).

    I can get this to work with a file that has only text, but if there is an image inserted into the file I get an error (62) - Input past end of file.

    Can anyone shed some light on this? Is there some function or procedure that I can pass a filename to and have it pass it to the default printer? Any insight will be appreciated.

    Thanks in advance
    Aaron Brennan
    Last edited by brenaaro; Sep 17th, 2001 at 03:03 PM.

  2. #2
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    If they are DOC files, then I can assume you have Word on your system. Just automate Word to print the document. Reference MS Object Library 8.0 or 9.0.

    VB Code:
    1. Option Explicit
    2. Private objWord As Word.Application
    3. Private worddoc As Word.Document
    4. Private Sub Command1_Click()
    5.  
    6.     On Error Resume Next
    7.    
    8.     ' grab Word if open
    9.     Set objWord = GetObject(, "word.application")
    10.    
    11.     ' if error here...Word wasn't open
    12.     If Err.Number <> 0 Then
    13.    
    14.         ' open it
    15.         Set objWord = CreateObject("Word.Application")
    16.        
    17.     End If
    18.     Err.Clear
    19.     On Error GoTo Word_Error
    20.    
    21.     ' open the document
    22.     Set worddoc = objWord.Documents.Open("C:\john.DOC")
    23.    
    24.     ' make Word visible but Minimized.
    25.     objWord.Application.Visible = True
    26.     objWord.WindowState = wdWindowStateMinimize
    27.    
    28.     ' print document
    29.     worddoc.PrintOut
    30.    
    31.     ' loop until printing done
    32.     While objWord.Application.BackgroundPrintingStatus > 0
    33.         DoEvents
    34.     Wend
    35.    
    36.     ' close document
    37.     worddoc.Close (wdDoNotSaveChanges)
    38.  
    39. Word_Error:
    40.     ' close Word
    41.     objWord.Quit
    42.    
    43.     ' clean up
    44.     Set objWord = Nothing
    45.     Set worddoc = Nothing
    46.  
    47.     Unload Me
    48.  
    49. End Sub

  3. #3

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391

    Print ok, another prob though

    I referenced Microsoft Word Object Library 9.0 but when I try to Set objWord as CreateObject("Word.Application"), I get error "ActiveX control cannot create application".

    I found out how to print the doc another way though, I just ran ShellExecute with "print" as the verb.

    I still need to know how to reference a Word application though, because now I am going to have a word document with a graphical header as a template, and I need to append text to the document. Is there another way to do that?

    Open "..." for Append as #liFileNum doesnt work because there's already a graphical header in the template..I could always use SendKeys but that takes a long time to execute and its unreliable.

    Any insight is appreciated, Thanks
    Last edited by brenaaro; Sep 18th, 2001 at 11:22 AM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    Try something along these lines:

    Dim WordObj As Word.Application
    Set WordObj = CreateObject("Word.Application")

  5. #5

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    That's exactly what I do.

    It raises error "429 ActiveX component can't create object".

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333
    And Word, is in fact, installed on each PC that is running the app, correct?

  7. #7
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Originally posted by brenaaro
    That's exactly what I do.

    It raises error "429 ActiveX component can't create object".
    That error could mean alot of things.

    What version of VB are you using ?? Which Service Pack ?? (need atleast Service Pack 3) What Windows version ?? What version of Office/Word ??


    Microsoft KB article on that error.

    http://support.microsoft.com/directo...icle.asp?ID=KB;EN-US;Q269330

  8. #8

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Im at work, the PC has MS Word 7.0 installed, on Windows 95. Im using VB6 Learning Edition (ugh, I know) and am downlaoding service pack 5 now (recently re-installed and forgot to do it) Maybe the Service Pack will fix it..

  9. #9
    Fanatic Member Patoooey's Avatar
    Join Date
    Aug 2001
    Location
    New Jersey, USA
    Posts
    774
    Originally posted by brenaaro
    Im at work, the PC has MS Word 7.0 installed, on Windows 95. Im using VB6 Learning Edition (ugh, I know) and am downlaoding service pack 5 now (recently re-installed and forgot to do it) Maybe the Service Pack will fix it..
    If not, then goto that MS site. Something about DCOM needing to be installed to get rid of that error on Win95 systems. Not sure if it also applies to VB learning Edition.


    429 Error

  10. #10

    Thread Starter
    Hyperactive Member brenaaro's Avatar
    Join Date
    Sep 2001
    Location
    Montreal, Canada
    Posts
    391
    Ok I'll check it out, thanks for the advice.

Posting Permissions

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



Click Here to Expand Forum to Full Width