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

Notifications

Announcements

Community site session details

Community site session details

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

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');

  }

 

}

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard