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 / Office script excel bl...
Power Automate
Unanswered

Office script excel blocks the movement of the excel file in power automate

(1) ShareShare
ReportReport
Posted on by 10
Hello,
I want to use power automate to run an office script on an Excel file, use some information in the file to make an approval request. If the Excel file is approved, the last step is to move it to another SharePoint folder.
The problem comes from moving the excel file, it is locked by the script:
 

{

  "status": 400,

  "message": "Le fichier « .xlsx » ne peut pas être déplacé, car il est en mode verrouillé.\r\nclientRequestId: 6eefdc95-d2c4-4b96-9a31-84f3695abc5d\r\nserviceRequestId: 20ae38a1-7080-9000-4824-79f771fd7cd3"

}

 

I tested with a very simple version of power automate, run the script and then move the document, it's the script that is blocking. I also tested with a 5min delay, it doesn't change anything.
Here is the office script, is there an error blocking the excel file?
 
function main(workbook: ExcelScript.Workbook😞 SelectedValuesToReturn {
  let sheet = workbook.getWorksheet("Page 1");
  let totalRow: number | undefined;
 
  let RespCellValue: string = sheet.getRange("B3").getValue() as string;

  // Ajouter la fonction de recherche
  let totalFound = false;
  let columnA = sheet.getRange("A01:A50").getValues();
  // Obtenir les valeurs de la colonne A
  for (let i = 0; i < columnA.length; i++) {
    if (columnA[i][0] === "PIECES JOINTES - NUMERO DE DEVIS :") {
      totalFound = true;
      totalRow = i + 2; // Ajouter 2 pour obtenir le numéro de ligne en dessous
      break; // Sortir de la boucle une fois que "total" est trouvé
    }
  }
    let DevisCellValue = sheet.getRange(`A${totalRow}`).getValue() as string;

  totalFound = false;
  totalRow = null;

  for (let i = 0; i < columnA.length; i++) {
    if (columnA[i][0] === "TOTAL") {
      totalFound = true;
      totalRow = i + 1; // Ajouter 1 pour obtenir le numéro de ligne
      break; // Sortir de la boucle une fois que "total" est trouvé
    }
  }
  let TotalCellValue = sheet.getRange(`F${totalRow}`).getValue() as number;

  return { Devis: DevisCellValue, Total: TotalCellValue, NomResp: RespCellValue }

}
interface SelectedValuesToReturn {
  Devis: string,
  Total: number;
  NomResp: string
}
 
Thank you in advance.
Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,726 Super User 2026 Season 1 on at

    Place the Office Scripts in a different file, and run them from there.  Don't put Office Scripts in data files.

  • Rtg65000 Profile Picture
    10 on at
    How is this possible on power automate?
    I saw a while technique as long as the file is not unlocked. After 5-6 min, the file is unlocked from the script and I can move it. It's not ideal but it works.
  • lbendlin Profile Picture
    8,726 Super User 2026 Season 1 on at

    It's a standard feature. When you use the "Run office scripts" action you can specify which Excel file to take the script code from.  Does not have to be (and should not be) the file you are operating on. You can indicate the target file in one of the script parameters.

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 252 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 169

#3
Haque Profile Picture

Haque 154

Last 30 days Overall leaderboard