Solved

print document

Posted on 2001-06-26
9
211 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
 

Author Comment

by:leachim
ID: 6230235
shankarkupra
nearly worked but error on the RichTextBox1.SelPrint
"argument not optional"
?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 

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 10 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

759 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now