ramj
Jan 24th, 2000, 05:51 PM
I am trying to print directly to a file.
When bringing up the common dialog I get an option to print to a file which when selected gives me a input box for printing.
How can this be achieved programmatically though VB ?
Thanks.
------------------
cfmoxey
Jan 24th, 2000, 10:06 PM
The following example uses a function, WriteOutput [if you need to have lots of paragraphs, each getting data separately, this will be whatever you construct to concatenate the text]; you supply the path and filename.ext. If you put code like this in a cmdButton_Click event, in no time at all, the file will be written. You don't have to use a RichTextBox, but if you have A LOT of text, you'll need to. You don't even have to use any TextBoxes, but they let you see, quickly, what you're doing. The keys to printing to a file are the Open, Print, and Close statements. --Carl
Private Sub cmdPrintFile_Click()
rtfOutputText.Text = WriteOutput(inputData)
' Export the text to the .txt file
Dim intFileNumber As Integer
intFileNumber = FreeFile
Dim strFilePath As String
strFilePath = "c:\path\" & "FileName.txt"
Open strFilePath For Output As #intFileNumber
Print #intFileNumber, rtfOutputText.Text
Close #intFileNumber
End Sub
[This message has been edited by cfmoxey (edited 01-25-2000).]