Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

print document

Posted on 2001-06-26
9
Medium Priority
?
268 Views
Last Modified: 2012-05-04
How can i print a document i.e wordpad rtf doc from vb
0
Comment
Question by:leachim
  • 4
  • 3
  • 2
9 Comments
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6227858
Project Name=PrintFile.exe

Selecting a standard.exe project....
Go to the components.....

Select the Microsoft richtextbox control
 (May be in the path directory \system\richtext32.ocx)

Then, do as follows:

Include a button---(Command1)
Include a richtextbox control---(richtextbox1)
Include another button -----(command2)


Here are the functions::::


private sub command1_Click()
richtextbox1.loadfile inputbox("Enter the rtf file name")
end sub

private sub command2.click()
RichTextBox1.SelStart = 1
RichTextBox1.SelPrint
end sub

That is all...........
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6228153
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

Dim lngResult As Long
lngResult = ShellExecute(Me.hwnd,"Print",strFile,0&,0&,vbMinimized)

where strFile is the full path to your  file



0
 

Author Comment

by:leachim
ID: 6228467
iboutchkine
looks good but i cant declare it in my general declaration for some reason?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:leachim
ID: 6230235
shankarkupra
nearly worked but error on the RichTextBox1.SelPrint
"argument not optional"
?
0
 

Author Comment

by:leachim
ID: 6230259
iboutchkine
works only on txt files
i need it to work on rtf doc files
thanks
0
 
LVL 28

Expert Comment

by:iboutchkine
ID: 6231140
leachim, it works perfectly on doc files. Right now I tried to print word document. Here the exact code:
Option Explicit
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 Sub Command1_Click()
Dim lngResult As Long
lngResult = ShellExecute(Me.hwnd, "Print", "c:\a.doc", 0&, 0&, vbMinimized)
MsgBox "done"
End Sub
0
 
LVL 3

Accepted Solution

by:
shankarkrupa earned 40 total points
ID: 6238786
Oh, very sorry leachim...I should have told this before...It expects a long argument...

It is nothing but your printer's hDC..just do change that line as follows:

RichTextBox1.SelPrint Printer.hDC

It is just a sort of identity for your program to the printer...That selPrint function takes any hDC...For example,you can even give the form.hWnd and see that all the text is printed in your form...


0
 

Author Comment

by:leachim
ID: 6238865
thats it nice one shankarkrupa
0
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6241976
Thank you...
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question