Istvanb
Istvanb

Reputation: 412

How to change excel workbook orientation and papersize (vb.net)

I need to convert a VBA script to vb.net using Visual Studio 2017. The original script is:

With ActiveSheet.PageSetup
    .Orientation = xlLandscape
    .PaperSize = xlPaperA3
End With

The code I tried in vb.net is:

Imports Excel = Microsoft.Office.Interop.Excel

...

With MonthSheet.PageSetup
    .Orientation = Excel.XlPageOrientation.xlLandscape
    .PaperSize = Excel.XlPaperSize.xlPaperA3
End With

Where the "MonthSheet" refers to one of the workbooks of the opened excel file. This code (however compiles) seems to delete all the workbooks of the excel file.

How can I change the orientation and papersize of an excel sheet from vb.net?

Upvotes: 0

Views: 1825

Answers (2)

Istvanb
Istvanb

Reputation: 412

The code I wrote was correct, it didnt work because of a programming error in a different subroutine.

Upvotes: 0

user7978226
user7978226

Reputation:

See this link for changing the Paper Size.

For changing the orientation of Excel Workbook.

xlWorkSheet.PageSetup.Orientation = Microsoft.Office.Interop.Excel.XlPageOrientation.xlLandscape

Upvotes: 1

Related Questions