web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Setup Print Area with ...
Power Automate
Answered

Setup Print Area with If condition Office Script

(0) ShareShare
ReportReport
Posted on by 12

I have five checkbox in power apps, I am passing those value to office script using power automate, I want to setup the print area based on the true or false value of those checkbox.

If QFM31 is true, Set Print area to A1:F21 of Sheet 1,

If QFM32 is true, Set Print area to A23:F50 of Sheet 1

If Firstarticle is true, Set Print area to A1:F21 of Sheet 2

If Setupsheet is true, Set Print area to A1:F21 of Sheet 3

If Specsheet is true, Set Print area to A1:F21 of Sheet 4,

 

When multiple are set Print area accordingly for Example:

if both QFM 31 and QFM 32 are selected, set A1:F21 OF Sheet1 as page1 and A23:F50 OF Sheet1 as Page 2

I wanted to do like that for every possible combination for these five.

 

I tried following but it is setting up print area to all no matter which one are true.

 

function main(workbook: ExcelScript.Workbook,

    QFM31string,

    QFM32string,

    Firstarticlestring,

    Setupsheetstring,

    Specsheetstring,

) {

  if (QFM31) {

    let sheet1 = workbook.getWorksheet('Sheet1');

    sheet1.getPageLayout().setPrintArea('A1:F21');

 

    if (QFM32) {

      sheet1.getPageLayout().setPrintArea('A1:F21,A23:F50');

    }

  }

  else if (QFM32) {

    let sheet1 = workbook.getWorksheet('Sheet1');

    sheet1.getPageLayout().setPrintArea('A23:F50');

  }

 

  if (Firstarticle) {

    let sheet2 = workbook.getWorksheet('Sheet2');

    sheet2.getPageLayout().setPrintArea('A1:F21');

  }

 

  if (Setupsheet) {

    let sheet3 = workbook.getWorksheet('Sheet3');

    sheet3.getPageLayout().setPrintArea('A1:F21');

  }

 

  if (Specsheet) {

    let sheet4 = workbook.getWorksheet('Sheet4');

    sheet4.getPageLayout().setPrintArea('A1:F21');

  }

 

}

Capture2.PNG
Categories:
I have the same question (0)
  • Verified answer
    Yutao Huang Profile Picture
    Microsoft Employee on at

    Hi @Rsapkota1 ,

     

    Have you tried troubleshooting it by running the script directly in Excel for the Web (from inside the script code editor)? You can simulate the Power Automate case by specifying default parameters to the `main` function:

    function main(workbook: ExcelScript.Workbook,
     QFM31: string = true,
     QFM32: string = true,
     Firstarticle: string = false,
     Setupsheet: string = false,
     Specsheet: string = false,
    ) {
     // ...
    }

     

    You can click on the "Run" button and see if the script runs as expected.

  • Rsapkota1 Profile Picture
    12 on at

    @Yutao I tried that and it is still setting print area to all

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 124 Super User 2026 Season 1

#2
Ellis Karim Profile Picture

Ellis Karim 52 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 50

Last 30 days Overall leaderboard