顯示具有 GAS 標籤的文章。 顯示所有文章
顯示具有 GAS 標籤的文章。 顯示所有文章

2026年10月20日 星期二

[研究]GAS(Google Apps Script)可以自動轉成為(Visual Basic for Applications)嗎?

[研究]GAS(Google Apps Script)可以自動轉成為(Visual Basic for Applications)嗎?

2026-10-20

可以協助將 GAS(Google Apps Script)轉換成 VBA(Visual Basic for Applications),但目前不能保證一鍵自動、完整且正確地轉換所有程式碼。

主要原因:GAS 和 VBA 使用不同的程式語言、執行環境及 API。 因此,通常需要將程式邏輯轉換,再重新設計與測試相關功能。

一、GAS 與 VBA 轉換比較

項目

自動轉換的可行性

說明

變數、條件判斷、迴圈

高

語法需要調整

加總、排序、資料篩選

高

可依需求改寫

讀取、寫入儲存格

中高

GAS 與 Excel VBA 的 API 不同

跨工作表處理

高

需要調整物件及工作表參照

跨檔案讀寫

中

取決於檔案位置及存取方式

Google 試算表、Gmail、Drive 整合

低至中

通常需要改用 Microsoft 服務或其他 API

網頁應用程式、觸發器

低

通常需要重新設計

以上是一般情況的估計,實際難度取決於程式內容。

二、實際範例:GAS 自動改寫為 VBA

假設您有一段 GAS,將 A1 與 A2 相加,結果寫入 A3。

原始 GAS 程式碼

function addCells() {
  const sheet = SpreadsheetApp
    .getActiveSpreadsheet()
    .getActiveSheet();

  const a1 = sheet.getRange("A1").getValue();
  const a2 = sheet.getRange("A2").getValue();

  sheet.getRange("A3").setValue(a1 + a2);
}

轉換後的 Excel VBA 程式碼

Sub AddCells()

    Dim ws As Worksheet
    Set ws = ActiveSheet

    Dim a1 As Double
    Dim a2 As Double

    a1 = ws.Range("A1").Value
    a2 = ws.Range("A2").Value

    ws.Range("A3").Value = a1 + a2

End Sub

兩段程式的功能相同,但執行環境不同:

  • GAS:在 Google 試算表中執行。

  • VBA:在桌面版 Microsoft Excel 中執行。

(完)

2026年10月19日 星期一

[研究]有 VBA 的 .xlsx 上傳 成為 Google 試算表後,會變成 GAS ? 還可以跑 ?

[研究]有 VBA 的 .xlsx 上傳 成為 Google 試算表後,會變成 GAS ? 還可以跑 ? 

2026-10-19

可以,但要注意一個關鍵觀念:Excel 的 VBA 不會因為把 .xlsx 上傳到 Google 雲端硬碟、再轉換成 Google 試算表,就自動變成 GAS(Google Apps Script)。

Excel VBA 與 Google Apps Script 是兩種不同的程式語言與執行環境。不過,您可以將 VBA 的功能改寫成 GAS,讓它在 Google 試算表中繼續執行。

一、Excel VBA 上傳 Google 試算表後會怎樣?

項目

Excel .xlsx / .xlsm

Google 試算表

主要程式語言

VBA

Google Apps Script(JavaScript)

原有 VBA 程式碼

.xlsm 可保存 VBA;.xlsx 不支援保存 VBA 專案

不會自動轉換成 GAS

一般儲存格公式

大部分可保留,部分函數可能有差異

轉換後需檢查相容性

工作表、格式、資料

通常可以匯入

可能需要檢查格式與功能差異

按鈕與巨集

可能無法正常運作

通常需要重新建立操作介面及 GAS

自動執行 VBA

只能在支援 VBA 的 Excel 環境執行

不能直接執行 VBA

改寫後的 GAS

不適用

可以在 Google 試算表中執行

特別注意:如果您的原始檔是 .xlsx,它本身通常就沒有儲存 VBA 專案;如果實際上有 VBA 巨集,原始檔通常是 .xlsm。

二、VBA 與 GAS 的轉換概念

例如,您在 Excel VBA 裡寫了以下程式:

Sub HelloWorld()
    Range("A1").Value = "Hello World"
End Sub

這段程式會將 Excel 工作表的 A1 儲存格填入 Hello World。

改寫成 GAS 後:

function helloWorld() {
  const sheet = SpreadsheetApp
    .getActiveSpreadsheet()
    .getActiveSheet();

  sheet.getRange("A1").setValue("Hello World");
}

功能相同,但程式碼並不相同。

(完)

2026年10月12日 星期一

[研究]GAS跨Google試算表讀、寫欄位值

[研究]GAS跨Google試算表讀、寫欄位值

2026-10-12

GAS如何取得 Google試算表 (假設稱為 AAA1) 的 A1 欄位值,加上 Google試算表 (假設稱為 AAA2) 的 A2 欄位值,填寫另一個 Google試算表 (假設稱為 AAA3) 的 A3 欄位值?

GAS (Google Apps Script)


function addThreeSpreadsheets() { // 三份 Google 試算表的 ID const id1 = "AAA1的試算表ID"; const id2 = "AAA2的試算表ID"; const id3 = "AAA3的試算表ID"; // 取得三份試算表 const ss1 = SpreadsheetApp.openById(id1); const ss2 = SpreadsheetApp.openById(id2); const ss3 = SpreadsheetApp.openById(id3); // 取得各試算表的工作表(第一個工作表) const sheet1 = ss1.getSheets()[0]; const sheet2 = ss2.getSheets()[0]; const sheet3 = ss3.getSheets()[0]; // 讀取 AAA1 的 A1、AAA2 的 A2 const value1 = Number(sheet1.getRange("A1").getValue()) || 0; const value2 = Number(sheet2.getRange("A2").getValue()) || 0; // 相加 const result = value1 + value2; // 寫入 AAA3 的 A3 sheet3.getRange("A3").setValue(result); }

如何取得試算表 ID?

例如 AAA1 的網址是:

https://docs.google.com/spreadsheets/d/1AbCdEfGhIjKlMnOpQrStUvWxYz123456789/edit#gid=0

其中:

- 試算表 ID:1AbCdEfGhIjKlMnOpQrStUvWxYz123456789

- gid=0:工作表分頁的 ID,不是試算表 ID。

將程式中的 AAA1的試算表ID 替換成真正的 ID 即可。

三種方法比較

方法

適用情況

寫入方式

openById()

已知試算表 ID

getRange("A1").setValue("資料")

openByUrl()

已知完整網址

getRange("A1").setValue("資料")

getSheetByName()

要指定工作表名稱

先取得指定工作表,再寫入

(完)

相關

2026年10月8日 星期四

[研究]免費 Google 帳戶使用者 vs 商用GWS Google Workspace 的 GAS 是否有每日6分鐘上限?

[研究]免費 Google 帳戶使用者 vs 商用GWS Google Workspace 的 GAS 是否有每日6分鐘上限?

2026-10-08

以 2026 年目前 Google Apps Script(GAS)官方配額來看:

項目 免費 Google 帳戶(@gmail.com) 商用 Google Workspace
單次 GAS 最長執行時間 6 分鐘 6 分鐘
觸發器每日總執行時間 90 分鐘/日 6 小時/日
URL Fetch 20,000 次/日 100,000 次/日
Email 收件者 100/日 1,500/日
同時執行數(每使用者) 30 30

Quotas associés aux services Google

https://ccn.web.tr/web-api/iframe-proxy?url=https%3A%2F%2Fdevelopers.google.com%2Fapps-script%2Fguides%2Fservices%2Fquotas%3Fhl%3Dfr

目前官方「公開配額」:沒有任何帳戶超過 6 分鐘

GAS 使用者 單次 Script 最長執行時間
個人 Google 帳戶(@gmail.com) 6 分鐘
一般 Google Workspace 6 分鐘
Business / Enterprise Workspace 官方公開配額仍列 6 分鐘

什麼情況可能看到 >6 分鐘?

可能是:

  1. Google 內部/特定 Workspace 帳戶的配額差異
  2. Google 後端曾經提供過較高的 runtime
  3. 配額或限制正在調整/灰度測試
  4. 執行的其實不是單一 Apps Script execution
  5. 某些特殊 Google 服務或執行模式造成「看起來」超過 6 分鐘

(完)

[研究]GAS 的 Step by Step 中文學習網站 ? (不是參考手冊)

[研究]GAS 的 Step by Step 中文學習網站 ? (不是參考手冊)

2026-10-08

排名 網站/課程 適合程度 教學方式 特點
🥇 1 Google Apps Script 基礎 Codelab ⭐⭐⭐⭐⭐ 逐步實作 官方、繁中、真正一步一步做
🥈 2 Vcdemy – Google Apps Script 教學 ⭐⭐⭐⭐⭐ 系列教學 繁中、觀念+實務、自動化導向
🥉 3 品科技 – GAS 從 0 到 1 ⭐⭐⭐⭐½ 手把手 很適合完全初學者
4 一起來學 App Script – Randy ⭐⭐⭐⭐ 實作導向 從程式基礎開始
5 GASO 學習平台 ⭐⭐⭐⭐ 學習路徑 比較像「課程地圖」,適合循序學

1.Google Apps Script 基礎程式碼研究室總覽

https://developers.google.com/apps-script/samples/fundamentals-codelabs?hl=zh-TW

2.Vcdemy:Google Apps Script 教學

https://www.vcdemy.com/gas/

3. 品科技:GAS「從 0 到 1」

https://www.pintech.com.tw/tw/article/551/best-ways-to-optimize-your-work-efficiency-with-google-apps-script-syntax

4. Randy「一起來學 App Script」

https://randy24.com/blog/introducing-how-learn-app-script/

5.亨利羊帶你 Google Apps Script 從入門到精通:放棄長篇大論的教學吧,你需要的只是一些精心設計的 prompt! 系列

https://ithelp.ithome.com.tw/users/20151846/ironman/8642

(完)

[研究]比較 Google Apps Script 和 Office Excel VBA 和 M365 Excel VBA、Office Scripts

[研究]比較 Google Apps Script 和 Office  Excel VBA 和 M365 Excel VBA、Office Scripts

2026-10-08

項目 Google Apps Script Office Excel VBA Microsoft 365 Excel VBA
開發語言 JavaScript 類 VBA VBA
主要平台 Google Workspace 雲端 Office 桌面版 Microsoft 365 桌面版
Excel ❌ ✅ ✅
Google Sheets ✅ ❌ ❌
Word ❌ ✅ ✅
PowerPoint ❌ ✅ ✅
Outlook ❌ ✅ ✅
Gmail ✅ ❌ ❌
Google Drive ✅ ❌ ❌
OneDrive 可透過 API 可 可,整合較佳
SharePoint API/服務 可 整合較佳
雲端執行 ⭐⭐⭐⭐⭐ ⭐ ⭐⭐~⭐⭐⭐
本機檔案操作 ⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
Windows 系統操作 ⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
網頁 API ⭐⭐⭐⭐⭐ ⭐⭐⭐ ⭐⭐⭐
排程執行 ⭐⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐
多人協作 ⭐⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐⭐⭐
伺服器部署 不需要 通常需要電腦 通常需要電腦
無人值守 ⭐⭐⭐⭐⭐ ⭐⭐ ⭐⭐⭐
學習門檻 中 中 中
Excel 細部控制 ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
Google 生態系 ⭐⭐⭐⭐⭐ ⭐ ⭐
Microsoft 生態系 ⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
適合大量 Excel 自動化 ⭐⭐⭐ ⭐⭐⭐⭐⭐ ⭐⭐⭐⭐⭐
適合跨平台 ⭐⭐⭐⭐⭐ ⭐ ⭐⭐
是否需要安裝 Excel ❌ ✅ ✅


比較 **GAS + VBA + Office Scripts**

Office Scripts 使用 TypeScript/JavaScript 類型語法,主要用於 Excel 網頁版與 Microsoft 365 雲端自動化。

項目 GAS VBA Office Scripts
全名 Google Apps Script Visual Basic for Applications Office Scripts
主要平台 Google Workspace Windows / Mac Office Microsoft 365
主要 Excel Google Sheets Excel 2021/2024/M365 Excel for Web / M365
執行位置 Google 雲端 本機 Excel 雲端
程式語言 JavaScript 類型 Visual Basic TypeScript
是否需安裝 ❌ ✅ Excel ❌
可離線執行 ❌ ✅ ❌
操作本機檔案 較有限 ★★★★★ ★
操作 Excel 工作表 ★★★★★ ★★★★★ ★★★★★
操作 Google Sheets ★★★★★ ❌ ❌
操作 Word ★★★★ ★★★★★ ★★★
操作 Outlook ★★★★ ★★★★★ ★★★
操作 PowerPoint ★★★ ★★★★★ ★★★
操作 Gmail ★★★★★ ❌ ❌
操作 OneDrive ★★★★ ★★★★ ★★★★★
操作 SharePoint ★★★★ ★★★ ★★★★★
HTTP / REST API ★★★★★ ★★★ ★★★★★
Webhook ★★★★★ ★★ ★★★★
排程執行 ★★★★★ ★★★ ★★★★★+Power Automate
事件觸發 ★★★★★ ★★★★★ ★★★
GUI 操作 ★★ ★★★★★ ★
Excel UserForm ❌ ★★★★★ ❌
巨集按鈕 ★★★ ★★★★★ ★★★
Power Automate 整合 ★★ ★★★ ★★★★★
Google Workspace 整合 ★★★★★ ★ ❌
Microsoft 365 整合 ★★★ ★★★★★ ★★★★★
適合企業流程 ★★★★ ★★★★ ★★★★★
適合個人 Excel ★★★ ★★★★★ ★★★★
學習門檻 ★★★ ★★★ ★★★★
雲端多人協作 ★★★★★ ★★ ★★★★★

比較 Google Apps Script 和 Office  Excel VBA 和 M365 Excel VBA、Office Scripts

項目 Google Apps Script Office 2021/2024 Excel VBA M365 Excel VBA Office Scripts
廠商 Google Microsoft Microsoft Microsoft
主要平台 Google Workspace Windows Office Microsoft 365 Microsoft 365
主要對象 Google Sheets 桌面 Excel 桌面 Excel Excel Web / M365
程式語言 JavaScript 類 VBA VBA TypeScript
是否免費 是 隨 Office 隨 M365 隨符合資格的 M365
是否需要安裝 不需要 需要 Excel 需要 Excel 不需要傳統 VBA 環境
Windows ✓ ✓ ✓ ✓
macOS ✓ ✓* ✓ ✓
瀏覽器 ✓ ✗ 部分功能 ✓
手機/平板 間接 ✗ 部分 ✓/有限
雲端執行 ✓ ✗ 部分 ✓
本機檔案操作 較弱 非常強 非常強 弱
Excel COM/Windows API ✗ ✓ ✓ ✗
操作 Excel Google Sheets 非常強 非常強 強
操作 Word/Outlook 透過 Workspace API ✓ ✓ ✗/有限
操作 Google Drive ✓ API/其他方式 API/其他方式 ✗
操作 OneDrive/SharePoint API 可 ✓ ✓
排程 ✓ Windows 工作排程器等 Power Automate 等 ✓
觸發器 非常強 VBA Event VBA Event 強
多人共同使用 非常適合 較弱 適合 非常適合
Web API 非常方便 可,但較麻煩 可 ✓
Power Automate ✗ 可透過其他方式 ✓ ✓
Git/版本控制 可 較不方便 較不方便 較適合
跨平台 非常好 較差 中等 非常好
學習難度 中 中~高 中~高 中
最適合 Google 生態系 本機 Excel 自動化 M365 企業自動化 M365 雲端 Excel 自動化

(完)

相關

Apps Script | Google for Developers
https://developers.google.com/apps-script

Google Apps Script 總覽
https://developers.google.com/apps-script/overview?hl=zh-tw

2026年10月7日 星期三

[研究]Google Apps Script 核心 Service(常用模組)

[研究]Google Apps Script 核心 Service(常用模組)

2026-10-07

內建 Google 服務
https://developers.google.com/apps-script/guides/services?utm_source=chatgpt.com&hl=zh-tw

Service 主要用途 常見操作
SpreadsheetApp Google 試算表 讀寫儲存格、工作表、格式
DocumentApp Google 文件 建立/修改文件、段落、表格
FormApp Google 表單 建立表單、題目、取得回覆
DriveApp Google Drive 檔案、資料夾、搜尋、搬移
GmailApp Gmail 寄信、搜尋、讀取郵件
CalendarApp Google 日曆 建立/修改行事曆事件
ContactsApp Google 聯絡人 聯絡人資料操作
SlidesApp Google 簡報 建立/修改簡報、投影片
UrlFetchApp HTTP/REST API 呼叫外部網站、API
Utilities 通用工具 日期、編碼、JSON、Blob、Sleep
PropertiesService 儲存設定值 API Key、系統設定、使用者設定
CacheService 暫存資料 暫存 API 回傳、降低重複查詢
LockService 鎖定/同步 避免多人同時執行造成資料衝突
ScriptApp Script 本身 Trigger、執行資訊、授權
Session 使用者/執行環境 使用者 Email、時區
HtmlService Web UI HTML 網頁、Web App 前端
ContentService HTTP 回應 Web App 回傳 JSON / Text
LanguageApp 翻譯 Google Translate
MailApp 寄信 發送 Email
Charts 圖表 建立圖表物件
Jdbc 資料庫 JDBC 連接 MySQL、SQL Server 等

⭐ 最值得先學的 10 個

  • SpreadsheetApp
  • DriveApp
  • GmailApp
  • CalendarApp
  • DocumentApp
  • FormApp
  • UrlFetchApp
  • Utilities
  • PropertiesService
  • ScriptApp



Google Apps Script │ ┌──────────────┼──────────────┐ │ │ │ Google資料 外部API GAS本身 │ │ │ SpreadsheetApp UrlFetchApp ScriptApp DriveApp API PropertiesService GmailApp CacheService CalendarApp LockService DocumentApp FormApp SlidesApp

例如:操作 Google Sheet


function test() { const ss = SpreadsheetApp.getActiveSpreadsheet(); const sheet = ss.getSheetByName("工作表1"); sheet.getRange("A1").setValue("Hello GAS"); }

例如:逐行讀取 Google Sheet



function processSheetData() { const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const data = sheet.getDataRange().getValues(); // 取得所有資料(二維陣列) // 跳過第一行標頭,從第二行開始迴圈 for (let i = 1; i < data.length; i++) { const name = data[i][0]; // A 欄 const email = data[i][1]; // B 欄 const status = data[i][2]; // C 欄 if (status === "待處理") { // 執行相對應的邏輯... sheet.getRange(i + 1, 3).setValue("已完成"); } } }

(完)

[研究]初次測試 Google Apps Script (GAS) 發信

[研究]初次測試 Google Apps Script (GAS) 發信

2026-10-07

一、 第一支 Apps Script:自動發送 Email

1.開啟 Google Sheet。

2.點擊選單列的 「擴充功能」 > 「Apps Script」。

3.將預設程式碼替換為以下內容:


function sendTestEmail() { // 取得目前試算表與工作表 const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); // 寫入資料到 A1 儲存格 sheet.getRange("A1").setValue("Hello Apps Script!"); // 發送測試郵件 (請換成你的 Email) const recipient = Session.getActiveUser().getEmail(); const subject = "Apps Script 測試成功!"; const body = "這是一封透過 Google Apps Script 自動發送的郵件。"; GmailApp.sendEmail(recipient, subject, body); Logger.log("郵件已發送至: " + recipient); }

4.點擊頂部的 「儲存」 圖示,再點擊 「執行」。

5.首次執行時,系統會要求 授權存取權限,點擊允許即可。

(完)

相關

Google Apps Script 總覽
https://developers.google.com/apps-script/overview?hl=zh-tw

Google Apps Script 是什麼?操作教學
https://gingerdesign.com.tw/google-apps-script-tutorial/