Question : VB.NET to Excel - setting orientation to landscape

I am using Visual Basic 2005 and am having a problem.

I am sending information to Microsoft Excel.  This works fine.  However, I want to tell it to set the page orientation to landscape.  This doesn't seem to work.  I'd guess that I am passing it the wrong statement, but I can't figure out the proper way to do it.

For a test, open a new project and paste this code (note that the code will fail on the line that tries to set the orientation):

        Dim oExcel As Object
        oExcel = CreateObject("Excel.Application")
        oExcel.Workbooks.Add()
        oExcel.Cells(1, 1).Value = "X"      
        oExcel.ActiveSheet.PageSetup.Orientation = oExcel.xllandscape
        oExcel.Visible = True
        oExcel = Nothing

I'm open to any ideas.

Answer : VB.NET to Excel - setting orientation to landscape

Hi chlade,

Try this....

    oExcel.ActiveSheet.PageSetup.Orientation = 2

The Orientation Constants have the following values....

    xlLandscape = 2
    xlPortrait = 1

Regards,

Wayne
Random Solutions  
 
programming4us programming4us