|
-
Sep 17th, 2001, 01:45 PM
#1
Thread Starter
Hyperactive Member
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.
-
Sep 17th, 2001, 04:58 PM
#2
Fanatic Member
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:
Option Explicit
Private objWord As Word.Application
Private worddoc As Word.Document
Private Sub Command1_Click()
On Error Resume Next
' grab Word if open
Set objWord = GetObject(, "word.application")
' if error here...Word wasn't open
If Err.Number <> 0 Then
' open it
Set objWord = CreateObject("Word.Application")
End If
Err.Clear
On Error GoTo Word_Error
' open the document
Set worddoc = objWord.Documents.Open("C:\john.DOC")
' make Word visible but Minimized.
objWord.Application.Visible = True
objWord.WindowState = wdWindowStateMinimize
' print document
worddoc.PrintOut
' loop until printing done
While objWord.Application.BackgroundPrintingStatus > 0
DoEvents
Wend
' close document
worddoc.Close (wdDoNotSaveChanges)
Word_Error:
' close Word
objWord.Quit
' clean up
Set objWord = Nothing
Set worddoc = Nothing
Unload Me
End Sub
-
Sep 18th, 2001, 10:40 AM
#3
Thread Starter
Hyperactive Member
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.
-
Sep 18th, 2001, 11:43 AM
#4
Try something along these lines:
Dim WordObj As Word.Application
Set WordObj = CreateObject("Word.Application")
-
Sep 18th, 2001, 12:38 PM
#5
Thread Starter
Hyperactive Member
That's exactly what I do.
It raises error "429 ActiveX component can't create object".
-
Sep 18th, 2001, 12:49 PM
#6
And Word, is in fact, installed on each PC that is running the app, correct?
-
Sep 18th, 2001, 12:49 PM
#7
Fanatic Member
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
-
Sep 18th, 2001, 01:03 PM
#8
Thread Starter
Hyperactive Member
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..
-
Sep 18th, 2001, 01:17 PM
#9
Fanatic Member
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
-
Sep 18th, 2001, 01:38 PM
#10
Thread Starter
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|