Excel XP, VB.NET, and PageSetup

PrimusGreg

New member
Joined
Apr 9, 2003
Messages
3
In the past Ive extensively used the Excel 9.0 Object library from within VB 6 to format excel spreadsheets from VB. Im now trying to do the same thing from within VB.NET using the Excel 10.0 object library and I cant seem to get it to work. On my laptop it seems to work fine because I have both Excel 97 and Excel XP installed. But, when I try to execute the same code on my desktop, the compiler throws and error on any function using the PageSetup object. Does anyone have any idea how I can access the PageSetup features from VB.NET using Excel XP? Ive just begun writing in VB.NET and so far its been a pretty steep learning curve.

Currently, Im trying to access the PageSetup properties by doing the following:

Code:
MyExcelApp.Worksheets("Sheet1" ).PageSetup.Orientation = xlLandscape

Another thing is that the compiler doesnt recognize any of the constants such as xlLandscape.
 
Code:
Dim oExcel As Excel.Application
oExcel = New Excel.Application()

Dim wb As Excel.Workbook = oExcel.Workbooks.Open("E:\Book1.xls")

Dim ws As Excel.Worksheet
ws = DirectCast(wb.Worksheets("Sheet1"), Excel.Worksheet)

ws.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape
ws.PrintOut()

wb.Close()

oExcel.Quit()
oExcel = Nothing
 
Back
Top