Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print file without losing formatting 1

Status
Not open for further replies.

JimFromLasVegas

Programmer
May 29, 2006
4
US
I have created a program that writes to a *.txt file. The file is formatted just like designed if I view through Word or Notepad. When I view through rtf control in VB6 it is formatted as well. The problem is when I try to print. All formatting and columns are lost.

Thanks,
 
Is there anyway to print directly from Notepad.exe? The file has a name and is saved properly. It displays perfectly in Notepad and Word?

Thanks again,
 

Hi and welcome to Tek-Tips. To get the best from the forum, please read faq222-2244.

You can use the ShellExecute DLL with the Print verb to print a document using it's associated program. In a public module (the declaration from 'Public' down to 'nShowCmd As Long) As Long' is all on one line):
Code:
Public 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
Public Function PrintThisDoc(formname As Long, FileName As String)
    On Error Resume Next
    Dim X As Long
    X = ShellExecute(formname, "Print", FileName, 0&, 0&, 3)
End Function

In your program, as needed
Code:
a = PrintThisDoc(Me,"c:\test.txt")

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Is this a fonts issue? The only way to get a text file to retain column spacing is to use a fixed width font like Courier.
 
First of all thank you very much for your time. Secondly, please excuse me if I ask dumb questions as I am in the learning mode.

I have created the module. I then created a command button with the following:

Private Sub Command1_Click()
a = PrintThisDoc(Me, "c:\archive.txt")
End Sub

When I click the Command button I get a type mismatch error. What obvious thing am I missing.

Thanks again,
 
Darn those cut&paste errors - they just cost me a life!

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top