How to make hundreds of URLs clickable in Google Docs

Posted on

How to make hundreds of URLs clickable in Google Docs – Despite Google Docs excellence, there can be problems in accessing the service. You may not be able to clear out storage space, share files, or are unable to access a document. Thankfully, many Google Docs problems are easy to fix. With Google Docs, specifically, whether you’re storing and managing your documents, there’s a decent chance you’ll run into some manner of murkiness along the way. We’re going to offer some typical Google Docs troubleshooting tips, then solve some specific Google Docs problems, like How to make hundreds of URLs clickable in Google Docs, and how to fix it.

I am migrating documents to Google Docs that contain many URLs. If I hit Enter after each one, the link becomes clickable. But I’m looking for a way to convert all URLs (text starting with http:// or https://) to be clickable.

Is there a macro, add-on or script I could run?

Answer :

I did some research on using Google Apps Scripts and I came up with this script that works for my needs. I hope it’s useful for someone else too.

function onOpen() {
    .addItem('Make URLs Clickable', 'makeUrlsClickable')

function makeUrlsClickable() {
  var urlRegex = 'http[s]?://[^ ]+';
  var body = DocumentApp.getActiveDocument().getBody();
  var urlElement = body.findText(urlRegex);  

  while (urlElement != null) {    
    var urlText = urlElement.getElement().asText();

    var startOffset = urlElement.getStartOffset();
    var endOffset = urlElement.getEndOffsetInclusive();

    urlText.setLinkUrl(startOffset, endOffset, getOnlyUrl(urlText.getText()));

    urlElement = body.findText(urlRegex, urlElement);

function getOnlyUrl(text) {
  var startOffset = text.indexOf('http');
  var endOffset = text.indexOf(' ', startOffset);

  if (endOffset === -1) {
    endOffset = text.length;

  return text.substring(startOffset, endOffset);

Copy and paste links which are already formatted as hyperlinks.

Here’s one easy way to do this:

  1. Paste your content into a site such as Convert Plain Text URLs to Link (or even a Stack Exchange question or answer draft).
  2. Copy the output
  3. Paste into your document (don’t hold shift)
  4. Remove formatting (this keeps the hyperlink but makes your font match)

This works in both Docs and Sheets, and probably others that I didn’t test.

I followed this tutorial: YouTube Link

Leave a Reply

Your email address will not be published.