マクロと自動タスクの使い方Macros and automatic tasks

コードの動きに合わせて、書き方と使い方をまとめています。How to write and run macros and schedule them.

マクロは、SQLの取得から、条件の判定、結果の保存、Excelへの出力までの手順を、テキストに書いて動かす機能です。自動タスクは、登録したマクロを、決めた時刻や間隔で動かします。ここでは、実際の動作に合わせて、使い方をまとめています。

試すためのデータは、試験用データベースに用意しました。SQLiteのファイルを開くだけで、このページの例を、そのまま動かせます。

1. 使い始めるまでの流れ

  1. SQLを登録する:SQLタブで書いたSELECTを、右側「マクロ用クエリ」から、名前を付けて登録します。マクロは、この名前で、SQLを呼び出します。
  2. マクロを書く:メニュー「ファイル」の「新しいマクロ」、または右側「マクロ」の「+」で、マクロ(拡張子 .vqm)を作ります。
  3. 検証する:「検証」で、接続名やクエリ名の誤りを、行番号つきで確認します。
  4. 登録(承認)する:「内容を確認して登録」で、本文、使うSQL、接続、出力先を確かめて、登録します。
  5. 実行する:「実行」で動かします。「実行履歴」に、結果が残ります。
  6. 自動で動かす:右側「自動タスク」から、スケジュールを登録します(5.)。

登録したあとで、本文、使うSQL、接続、マクロのタイムゾーンのどれかを変えると、もう一度、登録が必要です。登録した内容と違うものは、動かしません。

2. 最初の1本

いちばん短い形です。登録済みのクエリを実行して、結果をVeqSQLの「保存した結果」に追記します。

veqsql-macro 1
macro "Daily Summary"
use connection "TestSQLite"
run query "注文サマリ"
insert into "OrderSummary"

1行目は版の指定、2行目はマクロの名前、3行目は使う接続です。接続は、VeqSQLに登録した名前と、同じにしてください。

3. 変数・条件・繰り返し(veqsql-macro 2)

1行目を veqsql-macro 2 にすると、SQLの結果を変数として受け取り、条件や繰り返しを使えます。SQLの結果は、「列名のついた行の並び(配列)」です。

書き方意味
rows = query "クエリ名"登録済みのクエリを実行し、結果を変数に入れる
limit_amount = 20000変数に値を入れる
for row in rows … end配列の行を、1行ずつ処理する。列は row.列名 で読む
if 条件 … else … end条件で分ける。入れ子にできる
with 名前 = 式クエリの行の直後に書く。SQLの :名前 に、値を渡す
log 式値を、実行履歴に残す
save rows into "保存先"配列を、「保存した結果」に保存する
compare "保存先"
key "列"
with previous
前回の結果と比べる。比べた差の件数が、differences に入る
export excel "絶対パス.xlsx" from rows配列を、Excelに出力する
try … catch 変数 … end実行中の失敗を受け止めて、続きを書く
res = command "…"OSのコマンドを実行する(下の注意を参照)
  • 値:整数、小数、文字列("…")、true、false、null。日付と時刻は、date("2026-11-29")、datetime("2026-11-29 09:00:00")、decimal("100.50") で書きます。today と now は、実行を始めた時点の日付と時刻です(「設定」の「マクロのタイムゾーン」で決まります)。
  • 条件:= <> > < >= <= と、and、or、括弧が使えます。型が違う値の比較は、エラーにします。null = null は真で、nullと他の値の等しさは偽です。
  • コメント:-- または // から行末まで。/* … */ も使えます。
  • 文字:文字列は、JSONと同じ書き方です。パスは、C:/work/… のように、スラッシュで書くのが簡単です。
  • 上限:入れ子は16段、クエリは1つのマクロに100本、log は1回の実行で256件・1件500文字までです。無制限に繰り返す while はありません。実行時間やステップ数にも上限があります。

OSコマンドについて:command は、WindowsではCMD、Macでは /bin/sh で動きます。コマンドは、VeqSQLと同じ権限で動くため、DBの読み取り専用の設定では、制限できません。実行するコマンドは、登録の確認画面に表示されます。内容をよく確かめてから、登録してください。代入した変数に終了コードが入り、command_stdout と command_stderr に出力が入ります(それぞれ最大1MiB)。

4. 例

金額の大きい未発送の注文を探す

veqsql-macro 2
macro "未発送の確認"
use connection "TestSQLite"
rows = query "未発送の注文"
limit_amount = 20000
for row in rows
    if row.total_amount >= limit_amount
        log row.order_id
    end
end
log "確認が終わりました"

顧客ごとに、SQLへ値を渡す

veqsql-macro 2
macro "顧客ごとの注文件数"
use connection "TestSQLite"
customers = query "有効な顧客"
for cust in customers
    res = query "顧客の注文件数"
    with customer_id = cust.customer_id
    for line in res
        if line.order_count >= 4
            log cust.customer_name
        end
    end
end

登録したSQLの中に、WHERE customer_id = :customer_id のように書いておくと、with で渡した値が入ります。値は、SQLの文字列に連結せず、別に束縛します。

前回との差があるときだけ、Excelに出す

veqsql-macro 2
macro "注文サマリの変化を確認"
use connection "TestSQLite"
rows = query "注文サマリ"
save rows into "注文サマリ履歴"
compare "注文サマリ履歴"
key "order_id"
with previous
if differences > 0
    log "前回から変わった注文があります"
    export excel "C:/work/order_summary_{datetime}.xlsx" from rows
else
    log "前回から変化はありません"
end

最初の実行では、比べる前回の結果がないため、基準を保存して、そこで終わります。2回目から、差を調べます。出力先のファイル名の {datetime} と {run_id} は、実行のたびに置き換わります。

CSVを取り込む(veqsql-macro 1)

CSVとExcelの取り込みは、veqsql-macro 1 の書き方です。

veqsql-macro 1
macro "CSV inventory import"
use connection "TestSQLite"
import csv "C:/work/inventory.csv"
    encoding "utf8"
    delimiter ","
    headers true
    types text, integer, decimal
    replace "ImportedInventory"

文字コードは、utf8、utf16_le、utf16_be、shift_jis から選びます。型は、text、integer、decimal、date です。取り込み先は、「保存した結果」で、同じ名前のものを置き換えます。

5. 自動タスク

登録して承認したマクロを、決めた間隔や時刻で、自動で動かします。マクロのタブを開いた状態で、右側「自動タスク」の「+」を押します。

スケジュール設定するもの
間隔指定実行間隔(分)。1分から525,600分(1年)まで
指定日時に1回日付と時刻。過去の日時は、指定できません
毎日/毎週/隔週/毎月開始日(曜日や月の日の基準)、実行時刻、タイムゾーン
  • 休日の扱い:「休日・祝日の場合は翌営業日に実行」を選ぶと、「設定」の「営業日カレンダー」に従って、実行日をずらします。次回の予定は、一覧で確認できます。
  • 動く条件:VeqSQLが起動している間だけです。ウィンドウを閉じると、通知領域(トレイ)に残って続けます。終了すると止まり、Windowsのサインアウトや再起動でも止まります。
  • 同時に動く数:最大4件です。同じマクロは、重ねて動かしません。
  • 遅れたとき:予定の時刻から15秒を超えて気づいたときは、動かさず、「見送り」と記録します。溜まった分を、あとでまとめて動かすことはありません。存在しない日付や時刻も、見送ります。
  • 結果:完了、見送り、失敗を、通知と一覧で知らせます。くわしくは、マクロの「実行履歴」を見ます(最新200件、時刻はUTC)。
  • 止めるとき:一覧のタスクを右クリックして、停止を要求できます。解除は、実行中でないときにできます。解除しても、マクロのファイルと履歴は残ります。
  • Free版と無印版:Free版は、自動タスクを1件まで登録できます(画面には「登録 1/1(Free)」と出ます)。無印版は、制限がありません。

6. できること・できないこと

  • マクロが実行できる接続は、現在、SQLiteのファイル接続だけです。ほかのDBの接続では、「この接続先はマクロ実行にまだ対応していません」と表示されます。
  • マクロが実行するSQLは、読み取り(SELECT)だけです。更新系のSQLや、確認できない書き込みは、実行の前に、すべての手順をやめます。
  • マクロから、外部のDBを更新することはありません。「保存した結果」と、Excelへの出力が、書き込み先です。
  • Excelの出力は、新しいファイルだけを作ります。同じ名前のファイルがあるときは、上書きせず、エラーにします。
  • マクロの登録や承認、履歴、外部のマクロファイルは、バックアップに含まれません。
  • 実行履歴に残す log に、顧客の情報などの秘密を出さないよう、ご注意ください。

7. うまく動かないとき

表示確かめること
未登録/変更されました本文、SQL、接続を変えたあとは、もう一度「内容を確認して登録」を押します
登録済みクエリが見つからないマクロの query "…" の名前と、「マクロ用クエリ」の名前が、同じか確認します。クエリの名前を変えたときは、マクロの側も直します
接続が見つからない/複数あるuse connection の名前が、接続の名前と一致しているか、同じ名前の接続が複数ないか確認します
実行中のため、スキップした同じマクロが動いています。終わってから、もう一度動かします
承認鍵にアクセスできないOSの資格情報ストアが使えるか確認します
タイムゾーンを確認できない「設定」で、地域を選び直します

それでも解決しないときは、サポートまでお知らせください。

A macro is a text script that runs a sequence: fetch with SQL, branch on conditions, save results, export to Excel. An automatic task runs a registered macro on a schedule. This page follows how the app actually behaves.

Sample data is in the test databases page. Open the SQLite file and every example here runs as written.

1. From zero to a running macro

  1. Register the SQL: write a SELECT in a SQL tab and register it under a name from "Macro queries" on the right. Macros call SQL by that name.
  2. Write the macro: File > New macro, or "+" under "Macros" on the right. Macro files use the .vqm extension.
  3. Validate: catches wrong connection or query names, with line numbers.
  4. Review and register (approve): check the script, the SQL it uses, the connection and any output paths, then register.
  5. Run: results are kept in "Run history".
  6. Schedule it: add an automatic task (section 5).

If the script, the SQL it uses, the connection or the macro time zone changes after registration, it must be registered again. Anything that differs from what was approved does not run.

2. The shortest macro

veqsql-macro 1
macro "Daily Summary"
use connection "TestSQLite"
run query "注文サマリ"
insert into "OrderSummary"

Line 1 is the version, line 2 the macro name, line 3 the connection (use the name you gave it in VeqSQL). It runs the registered query and appends the result to "Saved results".

3. Variables, conditions, loops (veqsql-macro 2)

Start with veqsql-macro 2 to receive SQL results as variables. A result is an array of rows with named columns.

SyntaxMeaning
rows = query "name"Run a registered query into a variable
limit_amount = 20000Assign a value
for row in rows … endLoop over rows; read a column as row.column
if cond … else … endBranch; may be nested
with name = exprRight after a query line; passes a value to :name in the SQL
log exprWrite a value to run history
save rows into "target"Save an array to "Saved results"
compare "target"
key "column"
with previous
Compare with the previous result; the number of differences goes to differences
export excel "absolute path.xlsx" from rowsExport an array to Excel
try … catch var … endCatch a runtime failure and continue
res = command "…"Run an OS command (see the note below)
  • Values: integers, decimals, strings, true, false, null; date("2026-11-29"), datetime("2026-11-29 09:00:00"), decimal("100.50"). today and now are fixed at run start, in the macro time zone set in Settings.
  • Conditions: = <> > < >= <=, and, or, parentheses. Comparing different types is an error. null = null is true; null against anything else is false.
  • Comments: -- or // to end of line, or /* … */.
  • Strings follow JSON rules; write paths with forward slashes, such as C:/work/….
  • Limits: 16 nesting levels, 100 queries per macro, 256 log entries of 500 characters per run. There is no unbounded while, and run time and step counts are capped.

OS commands: command runs through CMD on Windows and /bin/sh on Mac, with the same privileges as VeqSQL, so the database read-only setting cannot restrict it. The command is shown in the approval screen; read it carefully. The exit code goes to the assigned variable, and output goes to command_stdout and command_stderr (1 MiB each at most).

4. Examples

Find large unshipped orders

veqsql-macro 2
macro "未発送の確認"
use connection "TestSQLite"
rows = query "未発送の注文"
limit_amount = 20000
for row in rows
    if row.total_amount >= limit_amount
        log row.order_id
    end
end
log "done"

Pass a value into SQL for each customer

veqsql-macro 2
macro "顧客ごとの注文件数"
use connection "TestSQLite"
customers = query "有効な顧客"
for cust in customers
    res = query "顧客の注文件数"
    with customer_id = cust.customer_id
    for line in res
        if line.order_count >= 4
            log cust.customer_name
        end
    end
end

Write WHERE customer_id = :customer_id in the registered SQL and the value from with is bound as a parameter, never concatenated into the SQL text.

Export to Excel only when something changed

veqsql-macro 2
macro "注文サマリの変化を確認"
use connection "TestSQLite"
rows = query "注文サマリ"
save rows into "注文サマリ履歴"
compare "注文サマリ履歴"
key "order_id"
with previous
if differences > 0
    log "changed"
    export excel "C:/work/order_summary_{datetime}.xlsx" from rows
else
    log "no change"
end

The first run has nothing to compare with, so it stores a baseline and stops there. Comparison starts on the second run. {datetime} and {run_id} in the file name are replaced on every run.

Importing CSV (veqsql-macro 1)

veqsql-macro 1
macro "CSV inventory import"
use connection "TestSQLite"
import csv "C:/work/inventory.csv"
    encoding "utf8"
    delimiter ","
    headers true
    types text, integer, decimal
    replace "ImportedInventory"

Encodings: utf8, utf16_le, utf16_be, shift_jis. Types: text, integer, decimal, date. The target is a "Saved results" entry of that name, which is replaced.

5. Automatic tasks

With the macro tab open, press "+" under "Automatic tasks" on the right.

ScheduleSettings
IntervalMinutes, from 1 to 525,600 (one year)
Once at a date and timeDate and time; past times are rejected
Daily / weekly / every other week / monthlyStart date (the anchor for weekday and day of month), time, time zone
  • Holidays: "Run on the next business day if a holiday" shifts the run according to the business calendar in Settings. The next planned run is shown in the list.
  • When it runs: only while VeqSQL is running. Closing the window keeps it in the notification area (tray). Quitting stops it, and so do sign-out and restart.
  • Concurrency: up to 4 tasks at once; the same macro never runs twice at the same time.
  • When late: if VeqSQL notices more than 15 seconds after the planned time, it does not run and records "skipped". Missed runs are never replayed. Dates or times that do not exist are skipped too.
  • Results: completed, skipped and failed runs are reported in a notice and in the list; details are in the macro's run history (latest 200, UTC).
  • Stopping: right-click a task to request a stop. A task can be removed when it is not running; the macro file and history remain.
  • Free and standard: Free registers one automatic task ("Registered 1/1 (Free)"). The standard edition has no limit.

6. What it can and cannot do

  • Macros currently run only on SQLite file connections. Other connections show "this connection is not yet supported for macros".
  • Macros run read-only SQL (SELECT) only. Updates and writes that cannot be reviewed are rejected before any step runs.
  • Macros never update external databases. Their outputs are "Saved results" and Excel files.
  • Excel export creates new files only; an existing file of the same name is an error, not overwritten.
  • Macro registrations, approvals, history and external macro files are not part of backups.
  • Do not log secrets such as customer data; log values are kept in run history.

7. When it does not run

MessageCheck
Not registered / changedAfter editing the script, SQL or connection, press register again
Registered query not foundThe name in query "…" must match the registered query name; if you renamed a query, fix the macro
Connection not found / several foundThe use connection name must match exactly, and only one connection may have it
Skipped because it is runningThe same macro is already running; wait for it
Approval key unavailableCheck that the OS credential store is available
Time zone unavailableChoose the region again in Settings

If it still does not work, contact support.