Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

476
Views
Looping through every starred file in my Drive folder and running a macro. No bugs but script not working...why?

I wrote the following script that looks through every starred file in Google Drive and executes two functions. The problem is, the functions are not actually doing their thing in the files. I'm new to scripting so any help or insight helps!

function runMacroOnStarredFiles(folder = DriveApp.getRootFolder()) {
  const ss = SpreadsheetApp.getActive();
  const files = folder.getFiles();
  while (files.hasNext()) {
    let file = files.next();
    if(file.isStarred() && file.getMimeType() == MimeType.GOOGLE_SHEETS) {
      SpreadsheetApp.openById(file.getId()).getSheets().forEach(sh => {
        if(sh.getName() !== null) {
          Newrowmacro();//the macro
    function Newrowmacro() {
  var spreadsheet = SpreadsheetApp.getActive();
  spreadsheet.getRange('19:19').activate();
  spreadsheet.getActiveSheet().insertRowsBefore(spreadsheet.getActiveRange().getRow(), 1);
  spreadsheet.getActiveRange().offset(0, 0, 1, spreadsheet.getActiveRange().getNumColumns()).activate();
  spreadsheet.getRange('A19').activate();
  spreadsheet.getCurrentCell().setFormula('=TODAY()');
  spreadsheet.getRange('H19').activate();
  spreadsheet.getCurrentCell().setFormula('=TODAY()');
  spreadsheet.getRange('M19').activate();
  spreadsheet.getCurrentCell().setFormula('=TODAY()');
  spreadsheet.getRange('A19').activate();
  spreadsheet.getActiveRangeList().setBorder(null, null, null, true, null, null, '#000000', SpreadsheetApp.BorderStyle.SOLID);
  spreadsheet.getRange('E22').activate();
};
        }
      });
    }
  }
  const subfolders = folder.getFolders()
  while (subfolders.hasNext()) {
    let subfolder = subfolders.next();
    runMacroOnStarredFiles(subfolder);
  }
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Run macro on all Starred Files

function runMacroOnStarredFiles(folder = DriveApp.getRootFolder()) {
  Logger.log(folder.getName());
  const ss = SpreadsheetApp.getActive();
  const files = folder.getFiles();
  while (files.hasNext()) {
    let file = files.next();
    Logger.log(file.getName());
    if (file.isStarred() && file.getMimeType() == MimeType.GOOGLE_SHEETS) {
      SpreadsheetApp.openById(file.getId()).getSheets().forEach(sh => {
        enternewrow();//the macro
      });
    }
  }
  const subfolders = folder.getFolders()
  while (subfolders.hasNext()) {
    let subfolder = subfolders.next();
    runMacroOnStarredFiles(subfolder);
  }
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!