Question about printing Excel file...

rahavtom

Well-known member
Joined
Apr 2, 2004
Messages
63
Hello!

Im using VB.NET and office XP. When I try to print a worksheet I get the following error:
"Exception from HRESULT : 0x800A03EC"

The code I use is:

Dim excelApp As New Excel.Application
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Open("C:\ClinicTech\Files\1.xls")
Dim excelWorksheet As Excel.Worksheet = CType(excelBook.Worksheets(1), Excel.Worksheet)
Makes Excel invisible to the user until spreadsheet is populated
excelApp.Visible = False
With excelWorksheet
Populate Excel spreadsheet
Try
.Range("E7").Value = iBPD

Catch ex As Exception
MsgBox(ex.Message)
End Try

Make Excel visible
excelApp.Visible = True
excelApp.Sheets.Select("Graph")
excelApp.Sheets.PrintOut()

End With

Thanks!
Tom.
 
Sheets.PrintOut should work, actually, but sometimes it can be erratic (and I dont know why, it is just a bit "buggy"). To print out a Worksheet, I would use:
Code:
Dim WS As Excel.Worksheet
WS = excelApp.Worksheets("Sheet1")
WS.PrintOut
It sounds by the name of your sheet, however, that "Graph" is probably a Chart object (sometimes called a "Chart Sheet"). In that case, I would use:
Code:
Dim Cht As Excel.Chart
Cht = excelApp.Charts("Graph")
Cht.PrintOut
If you need to print all your sheets, then I would make a loop, priting them one by one...
 
Back
Top