How to Add Custom Tabs in Google Docs Using Apps Script

Google Apps Script provides powerful automation features for Google Docs. One useful feature is inserting custom tabs within a document. In this blog post, we’ll create a script that adds two tabbed sections—“Advanced1” and “Advanced2”—allowing users to quickly navigate between them.


What the Script Does

✅ Inserts two tabbed sections labeled “Advanced1” and “Advanced2”.
✅ Allows users to quickly navigate to these sections.
✅ Uses Google Apps Script to dynamically create bookmarks for easy access.


Google Apps Script Code

function addTabsToGoogleDoc() {
var doc = DocumentApp.getActiveDocument();
var body = doc.getBody();

// Add first tab (Advanced1)
var advanced1 = body.appendParagraph("🔹 Advanced1 Section").setHeading(DocumentApp.ParagraphHeading.HEADING1);
var bookmark1 = doc.addBookmark(advanced1);

// Add second tab (Advanced2)
var advanced2 = body.appendParagraph("🔹 Advanced2 Section").setHeading(DocumentApp.ParagraphHeading.HEADING1);
var bookmark2 = doc.addBookmark(advanced2);

// Insert navigation menu at the top
var header = body.insertParagraph(0, "📌 Quick Navigation");
header.setHeading(DocumentApp.ParagraphHeading.HEADING1);

// Add clickable links to sections
var linkText1 = "➡ Go to Advanced1";
var linkText2 = "➡ Go to Advanced2";

var link1 = body.insertParagraph(1, linkText1);
link1.setLinkUrl(bookmark1.getId());

var link2 = body.insertParagraph(2, linkText2);
link2.setLinkUrl(bookmark2.getId());

DocumentApp.getUi().alert("Tabs added: Advanced1 and Advanced2!");
}

How the Script Works

1️⃣ Inserts “Advanced1” and “Advanced2” Sections

  • Uses body.appendParagraph() to add section headers.
  • Applies setHeading() to format them as Headings for better visibility.

2️⃣ Creates Bookmarks for Easy Navigation

  • The doc.addBookmark(paragraph) method stores a reference to the section.
  • These bookmarks allow users to jump between sections.

3️⃣ Adds Quick Navigation at the Top

  • Inserts a “Quick Navigation” menu at the start of the document.
  • Includes clickable links that take users to Advanced1 and Advanced2.

How to Run the Script

1️⃣ Open Google Docs and go to Extensions > Apps Script.
2️⃣ Copy and paste the above script into the editor.
3️⃣ Click Run → Select addTabsToGoogleDoc().
4️⃣ Check your Google Doc—you’ll see the navigation menu and sections!


Why This is Useful

🚀 Easy Navigation – Quickly jump between document sections.
📂 Better Organization – Structure your document for readability.
📌 One-Time Setup – Run the script once, and tabs stay in place.

This script is a simple yet powerful way to enhance Google Docs usability. Try it out and customize it for your workf