Skip to main content
Cadet | Tier 2
November 1, 2022
Question

can anyone assist with VBScript?

  • November 1, 2022
  • 2 replies
  • 262 views

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

 

    2 replies

    Paul Hawkins
    Navigator | Tier 3
    November 2, 2022

    @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

     

    Nathan.G1Author
    Cadet | Tier 2
    November 2, 2022

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

    Absolute legend!