-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathChangeHyperlinkName.js
More file actions
35 lines (28 loc) · 866 Bytes
/
Copy pathChangeHyperlinkName.js
File metadata and controls
35 lines (28 loc) · 866 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
RemcoE33
https://github.com/RemcoE33/apps-script-codebase
Changes all your selected hyperlinks text to the one you enter in the prompt.
*/
function onOpen(e){
SpreadsheetApp.getUi()
.createMenu('Utill')
.addItem('Change hyperlink text', 'hyperLinkNameChange')
.addToUi()
}
function hyperLinkNameChange(){
const ss = SpreadsheetApp.getActiveSpreadsheet();
const ui = SpreadsheetApp.getUi();
const name = ui.prompt('Link name?').getResponseText();
const dataRange = ss.getActiveRange();
const data = dataRange.getFormulas();
var array = [];
for (var i=0; i < data.length; i++){
var values = data[i];
var url = /"(.*?)"/.exec(values)[1];
var newUrl = '=HYPERLINK' + '("'+url+'","'+name+'")';
array.push([newUrl]);
}
Logger.log(data.length);
Logger.log(array);
dataRange.setFormulas(array);
}