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