Skip to main content

I have a VB Script that i have been shown and now i am wanting to expand on the foundation script. Id like it to change the orientation of the excel sheet to landscape, i have tried many combinations of the VB scripting but cannot get it.

 

This is a sample of the code here, the line with the "----" is what is failing each time as i cant figure out the correct syntax. can anyone help?

 

 

Set objExcel = CreateObject("Excel.application")

objExcel.application.visible=True

objExcel.application.displayalerts=false

set objExcelBook = objExcel.Workbooks.Open(InputFile)

objExcel.Sheets(SheetName).Select

------ objExcel.ActiveSheet.PageSetup.Orientation = xlLandscape ------

  

objExcelBook.SaveAs OutputFile, Ext

 objExcel.Application.Quit

 objExcel.Quit

 

@Nathan Gregor​ I believe the XlPageOrientation enumeration is only for excel VBA and not VB script

 

If you switch out the enumeration name (xlLandscape) for the value (2) does that work as expected?

 

See:

https://learn.microsoft.com/en-us/office/vba/api/excel.xlpageorientation

 


Paul, Thankyou so much!! This has done the trick, so many options at the fingertips now!

Absolute legend!


Reply