I was with the same problem and I the procedure below works well:
The CommonDialog I have is cdlKlinger. You must change it to the name you actually have.
On my procedure I dumped my outputs into a ListBox Control, I called lstCase01.
Here is the Procedure:
Private Sub cmdSave_Click()
' Printing in File.
With cdlKlinger
.CancelError = False
On Error GoTo ErrorHandler
If Err.Number = 32755 Or cdlCancel = True Then
GoTo ErrorHandler
Exit Sub
Else
.Flags = cdlOFNOverwritePrompt
.Filter = "All Files (*.*)|*.*|Text Files (*.txt)|*.txt|Data Files (*.dat)|*.dat"
.ShowSave
FileNumber = 1
FileName = .FileName
If FileName <> "" Then
Open FileName For Output As #FileNumber
Print #FileNumber, "Your Name or Title"
Print #FileNumber, "Your Profession"
Print #FileNumber, ""
Print #FileNumber, "Allowable Stress Design"
Print #FileNumber, ""
With lstCase01
For i = 0 To .ListCount
Print #FileNumber, .List(.ListIndex + i)
Next i
End With
Close #FileNumber
Else
Exit Sub
End If
End If
End With
Exit Sub
ErrorHandler:
MsgBox Err.Number & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & _
Err.Source, vbCritical, Me.Caption
Exit Sub
End Sub
And I am using also a Procedure to Print:
Private Sub cmdPrint_Click()
' Stablishing the CommomDialog Control
With cdlKlinger
.CancelError = False
On Error GoTo ErrorHandler
If (Err.Number = cdlCancel) Or (Err.Number = 32755) Or (cdlCancel = True) Then
' The User Canceled. Do nothing.
GoTo ErrorHandler
Exit Sub
Else
.Flags = (cdlPDReturnDC = True) And (cdlPDSelection = True) And _
(cdlPDHidePrintToFile = True) And _
(cdlPDDisablePrintToFile = True) And _
(cdlPDSelection = True) And _
(cdlPDAllPages = True)
.ShowPrinter
Printer.Orientation = .Orientation
' Printing in Printer
Printer.Font.Bold = True
Printer.Print vbTab & "Your Name"
Printer.Print vbTab & "Your Title and Profession" & vbCrLf
Printer.Print vbTab & "Allowable Stress Design" & vbCrLf
Printer.Print vbTab & Me.Caption & vbCrLf
Printer.Print vbTab & Format(Now, " mmm dd, yyyy (dddd)" & vbTab & "hh:mm:ss") & vbCrLf
Printer.Font.Bold = False
'
Printer.Print
Printer.Print
With lstCase01
For i = 0 To .ListCount
Printer.Print vbTab & .List(.ListIndex + i)
Next i
End With
Printer.NewPage
Printer.EndDoc
Printer.KillDoc
End If
End With
Exit Sub
ErrorHandler:
MsgBox "Error: " & Format$(Err.Number) & _
"Selecting Printer:" & Printer.DeviceName & vbCrLf & vbCrLf & _
Err.Description & vbCrLf & vbCrLf & _
Err.Source, vbCritical, Me.Caption
Exit Sub
End Sub
These two procedures work very good.
Albert