leachim
asked on
print document
How can i print a document i.e wordpad rtf doc from vb
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Heres the declare statement for the function and constants
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
Private Const SW_MAXIMIZE = 3
Private Const SW_MINIMIZE = 6
Private Const SW_NORMAL = 1
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long
ASKER
mhowling
after incorporating your declare statements
ShellExecute(Handle, "print", "c:\testfig.doc", Null, Null, SW_SHOWNORMAL);
comes back syntax error
any further suggestions?
after incorporating your declare statements
ShellExecute(Handle, "print", "c:\testfig.doc", Null, Null, SW_SHOWNORMAL);
comes back syntax error
any further suggestions?
Sorry about that leachim.
Okay the problem is with the Null's try replacing them with "" i.e
ShellExecute(Handle, "print", "c:\testfig.doc", "", "", SW_SHOWNORMAL)
ALTERNATIVELY
------------
Heres another way of doing it.
Private Sub Command1_Click()
Dim WordObj As Object
Set WordObj = GetObject("C:\testtemp\vbt est.doc")
WordObj.Activate
WordObj.PrintOut
WordObj.Close
Set WordObj = Nothing
End Sub
NOTE This is Late Binding. It can be done with early binding if you want by setting the project to reference Microsoft Word x.0 then rewritting the above as
Private Sub Command1_Click()
Dim WordObj As New Document
Set WordObj = WordObj.Application.Docume nts.Open(" C:\TestTem p\vbtest.d oc")
WordObj.Activate
WordObj.PrintOut
WordObj.Close
Set WordObj = Nothing
End Sub
These will print the document without the user ever realising that it has used Word. Whereas the ShellExecute method opens word prints the document and then closes word again.
Okay the problem is with the Null's try replacing them with "" i.e
ShellExecute(Handle, "print", "c:\testfig.doc", "", "", SW_SHOWNORMAL)
ALTERNATIVELY
------------
Heres another way of doing it.
Private Sub Command1_Click()
Dim WordObj As Object
Set WordObj = GetObject("C:\testtemp\vbt
WordObj.Activate
WordObj.PrintOut
WordObj.Close
Set WordObj = Nothing
End Sub
NOTE This is Late Binding. It can be done with early binding if you want by setting the project to reference Microsoft Word x.0 then rewritting the above as
Private Sub Command1_Click()
Dim WordObj As New Document
Set WordObj = WordObj.Application.Docume
WordObj.Activate
WordObj.PrintOut
WordObj.Close
Set WordObj = Nothing
End Sub
These will print the document without the user ever realising that it has used Word. Whereas the ShellExecute method opens word prints the document and then closes word again.
mhowling,
looks good, however, I have a question.
Will this work with just the application distributed files? (will it work if the workstation that this is distributed on doesn't have Word or doesn't have that version of Word?)
looks good, however, I have a question.
Will this work with just the application distributed files? (will it work if the workstation that this is distributed on doesn't have Word or doesn't have that version of Word?)
ASKER
HERES THE ANSWER CURTESY OF SHANKARKUPRA
RichTextBox1.LoadFile "whatever"
RichTextBox1.SelStart = 1
RichTextBox1.SelPrint Printer.hDC
Hi leachim,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:
Accept THuynh's comment(s) as an answer.
leachim, if you think your question was not answered at all or if you need help, you can simply post a new comment here. Community Support moderators will follow up.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will suggest to:
Accept THuynh's comment(s) as an answer.
leachim, if you think your question was not answered at all or if you need help, you can simply post a new comment here. Community Support moderators will follow up.
EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
==========
DanRollins -- EE database cleanup volunteer
Comment from expert accepted as answer
Computer101
E-E Moderator
Computer101
E-E Moderator
ASKER
looks promising.... only doesn't there need to be a declare statement before it?