rb982996
asked on
Printing an Excel Spreadsheet
In code, how would I print an excel spreadsheet. For instance, a user puts an excel name into a text box
c:\tmpDocs\sample.xls
Then the user clicks a button control and the spreadsheet is printed to the default printer.
c:\tmpDocs\sample.xls
Then the user clicks a button control and the spreadsheet is printed to the default printer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hey manojamin, this worked great. For extra points is there a way to automatically save linked data? The spreadsheet I am printing is recieving data via DDE and when ever I attempt to print it using the code you gave me I get asked a question if I would like to save the current linked data.
Thanks!
Thanks!
Try
xlObj.SaveWorkSpace("thefi lenameyouw ant") will save the excel application
or
Dim xlWB as Object
Set xlWB = xlObj.Workbooks.Open (filename:=<yourfilename>)
xlWB.Save 'will save the file
xlObj.SaveWorkSpace("thefi
or
Dim xlWB as Object
Set xlWB = xlObj.Workbooks.Open (filename:=<yourfilename>)
xlWB.Save 'will save the file
ASKER
Adjusted points to 150
I have seen a lot of example code that includes late-binding references (xlObj As Object). While this is perfectly acceptable, there is a lot of overhead, and slower speeds from late-binding. Plus you can't use the AutoComplete function of VB, because VB doesn't understand what type the object is until run-time.
The better way would be early-binding:
Add a reference to the Microsoft Office library, and Dim xlObj As New Excel.Application.
You could then ignore the CreateObject line.