10

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.

| improve this question | | | | |
  • 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
15

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")
| improve this answer | | | | |
  • Is it possible to do it without using the script editor? – pts Jan 25 '19 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 '19 at 7:05
  • 1
    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 '19 at 13:05
  • 1
    @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 '19 at 16:00
0

Notice that on the link you provided, there is a #gid=0 near the end of your link. Just copy this and put it inside the quotation marks.

Example:

=hyperlink("**#gid=0**","Link")
| improve this answer | | | | |
0

Proposition: (based on @Max Makhrov's answer)

allowing to both call the function from the script or by precising a sheet name from script like iterating through sheets and building a list of sheet urls.

(That's actually what I'm trying to do and brought me here)

function getSheetUrl(sht) {
  var ss = SpreadsheetApp.getActive(),
      url = '';

  sht = sht ? sht : ss.getActiveSheet();

  url = (ss.getUrl() + '#gid=' + ss.getSheetId());

  return url;
}
| improve this answer | | | | |
  • Thank you for the corrections, I'm a bit new to participating on StackExchange. – Guillaume M-D Apr 5 at 15:22

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.