0

I am trying to open multiple tabs at once but only the first and last will open, not the middle ones, where am I going wrong?

function openNewSheet(){
  opensheet1();
  opensheet2();
  opensheet3();
  opensheet4();
  opensheet5();
  opensheet6();  
}  

function opensheet1(){
  var url = "https://docs.google.com/spreadsheets/d/11qWurk-ZbT0dfC1nnQ_xoxdfiFmf2YcXtyhnPlCqK0Q";
  var html = "<script>window.open('" + url + "');google.script.host.close();</script>";
  var userInterface = HtmlService.createHtmlOutput(html);
  SpreadsheetApp.getUi().showModalDialog(userInterface, "Open Sheet"); }

function opensheet2(){
  var url2 = "https://docs.google.com/spreadsheets/d/1GyRO_m0vFcWL8wMOvR3m_skrYofnwLAJwsZAAjJvDak";
  var html2 = "<script>window.open('" + url2 + "');google.script.host.close();</script>";
  var userInterface2 = HtmlService.createHtmlOutput(html2);
SpreadsheetApp.getUi().showModalDialog(userInterface2, "Open Sheet2"); }

function opensheet3(){   
  var url3 = "https://docs.google.com/spreadsheets/d/1cKyVHmB3Eb5ycDGdqzro8qwfiSqTCZHafoVBSdJ4v7I";
  var html3 = "<script>window.open('" + url3 + "');google.script.host.close();</script>";
  var userInterface3 = HtmlService.createHtmlOutput(html3);
SpreadsheetApp.getUi().showModalDialog(userInterface3, "Open Sheet3"); }

function opensheet4(){
  var url4 = "https://docs.google.com/spreadsheets/d/1OSSbx9UojeK9jtPmnOlm_exzcEakC7fYGU0XQBG-AQw";
  var html4 = "<script>window.open('" + url4 + "');google.script.host.close();</script>";
  var userInterface4 = HtmlService.createHtmlOutput(html4);
SpreadsheetApp.getUi().showModalDialog(userInterface4, "Open Sheet4"); }

function opensheet5(){ 
  var url5 = "https://docs.google.com/spreadsheets/d/1U6xNOkRoGk6lhTuFekGr7rFEKrBPjB76wWqs1spDmPs";
  var html5 = "<script>window.open('" + url5 + "');google.script.host.close();</script>";
  var userInterface5 = HtmlService.createHtmlOutput(html5);
SpreadsheetApp.getUi().showModalDialog(userInterface5, "Open Sheet5"); }

function opensheet6(){
  var url6 = "https://docs.google.com/spreadsheets/d/16YjBCa0gAuZZ6VhcRyivQP2u5WiEgMrd-gXLSNKV9zI";
  var html6 = "<script>window.open('" + url6 + "');google.script.host.close();</script>";
  var userInterface6 = HtmlService.createHtmlOutput(html6);
SpreadsheetApp.getUi().showModalDialog(userInterface6, "Open Sheet6"); }

How do I make sure the middle four tabs open as well as the first and last one?

player0
  • 124,011
  • 12
  • 67
  • 124
roginla
  • 1
  • 1

1 Answers1

0

The problem occurs because Google Apps Script doesn't wait for a showModalDialog to finish and because a Google Apps Script dialog is slow to load the html code.

You could use Utilities.sleep(milliseconds) after your code opens a modal dialog with a milliseconds value big enough to allow the modal dialog to execute the html code.

An alternative is to use a single modal dialog to open all the spreadsheets. See Open a URL in a new tab (and not a new window)

Rubén
  • 34,714
  • 9
  • 70
  • 166