Create excel sheet in page break preview format

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
Hi everyone.

I am trying to create an excel spreadsheet in page break preview format. I have the following code, which does everything except save the xls in page break preview format. What have I missed? Thank you.

VB.NET:
        Dim objExcel As New Excel.Application
        Dim objWorkBooks As Excel.Workbooks
        Dim objWb As Excel.Workbook
        Dim objSheets As Excel.Sheets
        Dim objWorkSheet As Excel.Worksheet

        On Error Resume Next

        System.Windows.Forms.Cursor.Current = Cursors.WaitCursor
        System.Windows.Forms.Application.DoEvents()

        objWb = objExcel.Workbooks.Add

        objWorkBooks = objExcel.Workbooks

        'Must create a new sheet:
        objWorkSheet = objExcel.Sheets.Add(, objExcel.Worksheets(objExcel.Worksheets.Count))
        objWb = objWorkBooks.Item(1)
        objSheets = objWb.Worksheets
        objWorkSheet = CType(objSheets.Item(1), Excel.Worksheet)
        objWorkSheet.Activate()

        objWb.ActiveSheet.Range("A1").Value = "TEST"

        objWb.ActiveWindow.View = Excel.XlWindowView.xlPageBreakPreview

        objExcel.ActiveWorkbook.SaveAs(Application.StartupPath.ToString & "\Test.xls")

        objExcel.Visible = False
        objWorkBooks.Close()
        objWb.Close()
        objExcel.Quit()
        objWorkBooks = Nothing
        objWorkSheet = Nothing
        objWb = Nothing
        objExcel = Nothing
 
Back
Top