5

In Google Sheets, how do I create a hyperlink to this sheet?

I have a sheet which I'm about to download as PDF for archive. It would be useful to include a link in the sheet, pointing to itself, so that later I could click the PDF link and open the sheet again.

Of course I could copy the URL from the address bar, and insert the hyperlink:

=hyperlink("https://docs.google.com/spreadsheets/d/asdf/edit#gid=0","Link")

but I'm looking for a more general method.

  • What do you mean by "a more general method"? – Rubén May 31 '16 at 11:50
  • To link to the current sheet, even if the sheet is duplicated and re-used. – tomnexus May 31 '16 at 14:14
  • Looks that the answer by @Max_Makhrov fulfils that requirement. Did you already tried the suggested custom function? – Rubén May 31 '16 at 14:21
11

Open menu Tools → Script Editor and paste this code:

function getSheetUrl() {
  var SS = SpreadsheetApp.getActiveSpreadsheet();
  var ss = SS.getActiveSheet();
  var url = '';
  url += SS.getUrl();
  url += '#gid=';
  url += ss.getSheetId(); 
  return url;
}

Close The Script Editor.

And use this formula:

=hyperlink(getSheetUrl(),"Link")
  • Is it possible to do it without using the script editor? – pts Jan 25 at 17:26
  • Create the url like this: #gid=215455 where 215455 is your sheet id. Copy it from the browser address bar. – Max Makhrov Jan 28 at 7:05
  • Is it possible to do it within a formula, i.e. is there an equivalent of getSheetId() which I can call from a formula, without writing or using a script, e.g. =hyperlink(concatenate("#gid=",getSheetId()),"Link") ? – pts Jan 29 at 13:05
  • @pts, as far as I know, there's no built-in formula. I'd love to have such formula, too. Hope, Google will implement it soon. – Max Makhrov Jan 30 at 16:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.