WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

OLE with Excel
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Print Excel Worksheets


Printing Worksheets

The code in this section is used to print every worksheet in a workbook. It does this by looping through all of the worksheets and populating an array with the sheets.

#DefineFunction PrintSheets(XLS)
    ;   Start excel here
   objXLS = objectopen("Excel.Application")
   objXLS.visible = @true
   objWrkBks = objXLS.workbooks
   objWrkBk = objWrkBks.open(XLS)
   ;   setup the sheets var...
   objSheets = objWrkBk.Sheets
   count = objSheets.Count
   arrSheets = ArrDimension(count)
   For wCtr = 1 To count               
      objSheet =  objSheets.Item(wCtr)
      arrSheets[wCtr-1] = objSheet.Name
      objSheet.PrintOut(::preview=@False)
      objSheet = 0
    Next
    objSheets = 0
    objWrkBk = 0
    objWrkBks = 0
    objXLS.Quit()
    objXLS = 0
    Return arrSheets    
#EndFunction

PrintSheets("C:\Temp\Data\myExcelFile.xls")

Article ID:   W17160
File Created: 2007:07:03:14:28:32
Last Updated: 2007:07:03:14:28:32