Script function openAllLinks() could not be found

68 views
Skip to first unread message

Matt Bowen

unread,
Feb 7, 2024, 7:16:19 PMFeb 7
to Google Apps Script Community
Hi, 

I am trying to make this script work so that when you press the button all of the hyperlinks open.
I can't seem to figure out what I've done wrong!
I have very little experience with this and have tried to use AI to help so might not have set it up correctly..??

Screenshot 2024-02-08 001351.png

Any suggestions?

Here is the google sheet I'm using:

Thank you for any ideas - in advance, 
Matt

This is the script I've used:

function openAllLinks() {
  // Get the selected range
  const selection = SpreadsheetApp.getActiveSheet().getActiveRange();

  // Filter for cells containing hyperlinks
  const withLinks = selection.getRichTextValues()
    .map((row, rowIndex) => row.map((cellRichTextValue, colIndex) => {
      // Check if cell contains hyperlinks
      const links = cellRichTextValue.getRuns().filter(run => run.getLinkUrl());
      return links.length > 0 ? links[0].getLinkUrl() : null; // Get the first link URL
    }))
    .filter(row => row.some(cell => cell !== null));

  // Open each hyperlink in a new browser tab
  withLinks.forEach(row => {
    row.forEach(cell => {
      if (cell) {
        UrlFetchApp.fetch(cell, {muteHttpExceptions: true});
      }
    });
  });

  // Show a confirmation message
  SpreadsheetApp.getUi().alert('Links opened successfully!');
}

Keith Andersen

unread,
Feb 7, 2024, 7:24:06 PMFeb 7
to google-apps-sc...@googlegroups.com
On your butto when you assigned the function, you added () to the function name. You only need the name - not ()

I removed those and the function did run.

However, it did not open links in new tabs.

--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/57c4b71d-4739-43a8-b928-b6bf4aa8183fn%40googlegroups.com.

Emerson Maia

unread,
Feb 7, 2024, 9:15:39 PMFeb 7
to google-apps-sc...@googlegroups.com
you can try something like this


const openAllLinks = () => { // Get the selected range const selection = SpreadsheetApp.getActiveSheet().getActiveRange(); // Filter for cells containing hyperlinks const withLinks = selection.getRichTextValues().flatMap((row) => row.flatMap((cellRichTextValue) => { const links = cellRichTextValue.getRuns().filter(run => run.getLinkUrl()).map(run => run.getLinkUrl()); return links.length > 0 ? links[0] : null; // Get the first link URL }).filter(url => url !== null) ); // Open each hyperlink in a new browser tab withLinks.forEach((url) => { if (url) { UrlFetchApp.fetch(url, {muteHttpExceptions: true}); } }); // Show a confirmation message SpreadsheetApp.getUi().alert('Links opened successfully!'); }


Matt Bowen

unread,
Feb 20, 2024, 3:52:33 PMFeb 20
to Google Apps Script Community
Hi, many thanks for having a look at this query for me - Emerson, how do I format the script you posted as it is all in one paragraph? 
Kind regards, 
Matt

Reply all
Reply to author
Forward
0 new messages