![]() |
Printing Text Files from VBA
I'm working on a large application that now calls APL through an ActiveX
server. APL manages a bunch of databases, does calculations, formats reports, and prints them to the default printer. All interface with the user is already in Excel/VBA. I'm working to eliminate the APL. Access can take over the APL component files. VBA, of course, can handle the calculations, and in some cases more easily, using the built in BetaDist and GammaLn functions. With help here I'm now reading and writing small text files, which APL did before. Next along this line is to print them. In APL I have a rather sophisticated formatting routine that the APL people wrote for me. But to start I'd be happy in just sending the text file to the printer. Maybe someday I can replicate the formatting that APL does, especially the fit to page capability. Don <donwiss at panix.com. |
Printing Text Files from VBA
Have you tried automating Word using VBA from Excel?
http://word.mvps.org/FAQs/index.htm When you get to the site, choose the "Office Interdevelopment" tab and start with the link to control Word from Excel. Steve "Don Wiss" wrote in message ... I'm working on a large application that now calls APL through an ActiveX server. APL manages a bunch of databases, does calculations, formats reports, and prints them to the default printer. All interface with the user is already in Excel/VBA. I'm working to eliminate the APL. Access can take over the APL component files. VBA, of course, can handle the calculations, and in some cases more easily, using the built in BetaDist and GammaLn functions. With help here I'm now reading and writing small text files, which APL did before. Next along this line is to print them. In APL I have a rather sophisticated formatting routine that the APL people wrote for me. But to start I'd be happy in just sending the text file to the printer. Maybe someday I can replicate the formatting that APL does, especially the fit to page capability. Don <donwiss at panix.com. |
Printing Text Files from VBA
the easiest would be to open the file in excel and print it from there. Or
you could use the low level fileio and parse it into excel, then print it from excel Another would be to open it in word and print it from there You can wite it directly to the printer a line at a time or perhaps more than a line at a time, same as you read it in. -- Regards, Tom Ogilvy "Don Wiss" wrote in message ... I'm working on a large application that now calls APL through an ActiveX server. APL manages a bunch of databases, does calculations, formats reports, and prints them to the default printer. All interface with the user is already in Excel/VBA. I'm working to eliminate the APL. Access can take over the APL component files. VBA, of course, can handle the calculations, and in some cases more easily, using the built in BetaDist and GammaLn functions. With help here I'm now reading and writing small text files, which APL did before. Next along this line is to print them. In APL I have a rather sophisticated formatting routine that the APL people wrote for me. But to start I'd be happy in just sending the text file to the printer. Maybe someday I can replicate the formatting that APL does, especially the fit to page capability. Don <donwiss at panix.com. |
Printing Text Files from VBA
On Sat, 8 Jan 2005 14:50:10 -0500, Tom Ogilvy wrote:
the easiest would be to open the file in excel and print it from there. Or you could use the low level fileio and parse it into excel, then print it from excel Another would be to open it in word and print it from there You can wite it directly to the printer a line at a time or perhaps more than a line at a time, same as you read it in. Actually I miswrote my request. The text I want to print is already in Excel as strings. For now I used Excel to print. It is a bit slow the way I did it. I'm sure writing it directly to the printer would be faster, but at least the Excel way lets me play with formatting. I'll probably start enhancing the below. At least change the format based on the ending value of j. Sub PrintText(S As String) ' arg: CR/LF delimited text string ' reads: global ViewerType Dim SheetName As String Dim i As Integer, j As Integer, T As String Application.StatusBar = "Printing..." SheetName = ActiveSheet.Name ' create hidden sheet Application.ScreenUpdating = False Sheets.Add Range("A:A").ColumnWidth = 100 Columns("A:A").WrapText = True Cells.Font.Name = "Courier New" ' place text on sheet For i = 1 To Len(S) If Mid(S, i, 1) < Chr(13) Then T = T & Mid(S, i, 1) Else j = j + 1 Cells(j, 1).Value = T T = "" i = i + 1 End If Next i With ActiveSheet With .PageSetup If ViewerType = 1 Then .CenterHeader = "WC Parameter History" ElseIf ViewerType = 2 Then .CenterHeader = "Sheet Instructions for: " & SheetName End If .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 1 End With .PrintOut ' delete temp sheet Application.DisplayAlerts = False .Delete Application.DisplayAlerts = True End With ' put people back where they were Sheets(SheetName).Select Application.StatusBar = False End Sub Don <donwiss at panix.com. |
All times are GMT +1. The time now is 07:32 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com