![]() |
Printing specific excel worksheets in VB.NET
Hi,
I feel like this should be obvious, but I'm missing something. I want to print specific worksheets in an Excel workbook (ie, sheets 1 through 7 of a 13 sheet book). I want them to go out as one print job, not 7 separate print jobs. I tried "selecting" sheets one through seven, but all the other sheets default to "selected" when I open the workbook, so the print job always prints all 13 sheets (code below). I havent found a way to "unselect" sheets (setting the select property to false give me an error). Any help would be much appreciated. Thanks. ECD Dim xlApp As New Microsoft.Office.Interop.Excel.Application Dim xlBook As Microsoft.Office.Interop.Excel.Workbook Dim SelectedSheets(6) As Integer 'Open excel sheet, load data xlBook = CType(xlApp.Workbooks.Add, _ Microsoft.Office.Interop.Excel.Workbook) xlBook = OpenExcelWorkBook(xlApp) SelectedSheets(0) = 1 SelectedSheets(1) = 2 SelectedSheets(2) = 3 SelectedSheets(3) = 4 SelectedSheets(4) = 5 SelectedSheets(5) = 6 SelectedSheets(6) = 7 xlBook.Sheets(SelectedSheets).Select() xlBook.PrintOut() xlBook.Close(False) xlBook = Nothing xlApp.Quit() xlApp = Nothing |
Printing specific excel worksheets in VB.NET
Dim xlApp As New Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook Dim SelectedSheets(6) As Integer 'Open excel sheet, load data xlBook = CType(xlApp.Workbooks.Add, _ Microsoft.Office.Interop.Excel.Workbook) xlBook = OpenExcelWorkBook(xlApp) SelectedSheets(0) = 1 SelectedSheets(1) = 2 SelectedSheets(2) = 3 SelectedSheets(3) = 4 SelectedSheets(4) = 5 SelectedSheets(5) = 6 SelectedSheets(6) = 7 xlBook.Sheets(SelectedSheets).PrintOut() xlBook.Close(False) xlBook = Nothing xlApp.Quit() xlApp = Nothing -- Regards, Tom Ogilvy " wrote: Hi, I feel like this should be obvious, but I'm missing something. I want to print specific worksheets in an Excel workbook (ie, sheets 1 through 7 of a 13 sheet book). I want them to go out as one print job, not 7 separate print jobs. I tried "selecting" sheets one through seven, but all the other sheets default to "selected" when I open the workbook, so the print job always prints all 13 sheets (code below). I havent found a way to "unselect" sheets (setting the select property to false give me an error). Any help would be much appreciated. Thanks. ECD Dim xlApp As New Microsoft.Office.Interop.Excel.Application Dim xlBook As Microsoft.Office.Interop.Excel.Workbook Dim SelectedSheets(6) As Integer 'Open excel sheet, load data xlBook = CType(xlApp.Workbooks.Add, _ Microsoft.Office.Interop.Excel.Workbook) xlBook = OpenExcelWorkBook(xlApp) SelectedSheets(0) = 1 SelectedSheets(1) = 2 SelectedSheets(2) = 3 SelectedSheets(3) = 4 SelectedSheets(4) = 5 SelectedSheets(5) = 6 SelectedSheets(6) = 7 xlBook.Sheets(SelectedSheets).Select() xlBook.PrintOut() xlBook.Close(False) xlBook = Nothing xlApp.Quit() xlApp = Nothing |
All times are GMT +1. The time now is 09:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com