Googleカレンダーは、CSVファイル等を使った予定の一括登録に対応していますが、その一方で、予定の一括削除はできません。(カレンダーごと完全に削除することはできます・・・)
つまり、大量に誤った予定を登録してしまった場合、画面から一つずつポチポチ削除することになるのですが、その操作もわりと不便で手間がかかります。
しかし、Google Apps Scriptを使えば、指定した期間の予定を一括削除したり、複数の予定を指定して一括削除することができますので、その方法を紹介します。
準備・前提知識
- 新規のスプレッドシートを作成してください。タイトルやシート名等は適当で構いません
- そのスプレッドシートから、スクリプトエディタを起動してください。
拡張機能メニューより、Apps Scriptを起動します。

あらかじめ入力されているコード(myFunction)を削除し、当記事のコードを貼り付けます。
貼り付け後、保存してください。

- 処理する対象のカレンダーのIDを確認しておいてください。
対象のカレンダーのメニューボタン > 設定と共有

「カレンダーの統合」にカレンダーIDが表示されます。

期間を指定して予定を一括削除する
期間中の予定をすべて削除する場合はこの方法でOKです。
もし、削除したい予定と削除したくない予定が混在している場合は、この方法は不適切ですので、次の方法に進んでください。
まずは、期間を指定して予定を一括削除するコードを紹介します。
スクリプトエディタに次のコードを貼り付けて、保存してください。
- 2行目のカレンダーのIDはご自身のカレンダーのIDに書き換えてください。
- 3行目、4行目には、削除する期間の開始・終了を指定してください。
下記コードの例では、2023/4/1 0:00 から 2024/3/31 24:00 までの予定が削除対象になります。
function deleteEvents() {
const calendar = CalendarApp.getCalendarById('xxxxxxxxxxx@group.calendar.google.com');
const startTime = new Date('2023/4/1 0:00');
const endTime = new Date('2024/3/31 24:00');
const events = calendar.getEvents(startTime, endTime);
events.forEach(event => {
const title = event.getTitle();
const start = Utilities.formatDate(event.getStartTime(), 'JST', 'yyyy-MM-dd HH:mm');
const end = Utilities.formatDate(event.getEndTime(), 'JST', 'yyyy-MM-dd HH:mm');
Logger.log(`${title} (${start} - ${end})`);
event.deleteEvent();
})
}
続いて、deleteEvents関数を選択し、▷実行します。
初めて実行する際は、承認を求められますので、下記の手順で承認してください。

「承認が必要です」というダイアログが表示されますので、権限を確認 をクリックします。
* この部分の解説画像は、他の記事から流用しているため、実際のものと若干異なる場合があります。

このスクリプトを使うGoogleアカウントを選択します。

(この画面が表示された場合のみ)左下の 詳細 をクリックします。

(この画面が表示された場合のみ)左下の プロジェクト名(安全ではないページ)に移動 をクリックします。

右下の 許可 をクリックします。

「承認が必要です」というダイアログが表示されますので、権限を確認 をクリックします。
* この部分の解説画像は、他の記事から流用しているため、実際のものと若干異なる場合があります。

このスクリプトを使うGoogleアカウントを選択します。

(この画面が表示された場合のみ)左下の 詳細 をクリックします。

(この画面が表示された場合のみ)左下の プロジェクト名(安全ではないページ)に移動 をクリックします。

右下の 許可 をクリックします。

実行ログに、削除したカレンダーの予定が表示されます。
「実行完了」のログが表示されれば、指定した期間の予定がすべて削除されているはずです。カレンダーの画面で確認してみてください。

予定を指定して一括削除する
続いて、複数の予定を自分で選んで一括削除する方法を紹介します。
スクリプトエディタに次のコードを貼り付けて、保存してください。
- 2行目、28行目のカレンダーのIDはご自身のカレンダーのIDに書き換えてください。
- 3行目、4行目には、削除対象期間の開始・終了を指定してください。
下記コードの例では、2023/4/1 0:00 から 2024/3/31 24:00 までの期間が対象になります。
function getEvents() {
const calendar = CalendarApp.getCalendarById('xxxxxxxxxxx@group.calendar.google.com');
const startTime = new Date('2023/4/1');
const endTime = new Date('2024/3/31 24:00');
const events = calendar.getEvents(startTime, endTime);
const sheet = SpreadsheetApp.getActive().getActiveSheet();
sheet.clear();
sheet.appendRow(['ID', 'Title', 'Description', 'StartTime', 'EndTime', 'Creators', 'Location', 'LastUpdated']);
events.forEach(event => {
sheet.appendRow([
event.getId(),
event.getTitle(),
event.getDescription(),
event.getStartTime(),
event.getEndTime(),
event.getCreators().join(','),
event.getLocation(),
event.getLastUpdated(),
])
});
}
function deleteSpecifiedEvents() {
const sheet = SpreadsheetApp.getActive().getActiveSheet();
const records = sheet.getDataRange().getValues().slice(1);
const startTime = records.reduce((acc, value) => { return !acc || value[3] < acc ? value[3] : acc }, null);
const endTime = records.reduce((acc, value) => { return !acc || acc < value[4] ? value[4] : acc }, null);
const calendar = CalendarApp.getCalendarById('xxxxxxxxxxx@group.calendar.google.com');
const calendarEvents = calendar.getEvents(startTime, endTime);
records.forEach(record => {
const event = calendarEvents.find(event => event.getId() === record[0]);
const title = event.getTitle();
const start = Utilities.formatDate(event.getStartTime(), 'JST', 'yyyy-MM-dd HH:mm');
const end = Utilities.formatDate(event.getEndTime(), 'JST', 'yyyy-MM-dd HH:mm');
Logger.log(`${title} (${start} - ${end})`);
event.deleteEvent()
})
}
まずは、予定の一覧を取得します。getEvents関数を選択し、▷実行してください。
初めて実行する際は、承認を求められますので、下記の手順で承認してください。

「承認が必要です」というダイアログが表示されますので、権限を確認 をクリックします。
* この部分の解説画像は、他の記事から流用しているため、実際のものと若干異なる場合があります。

このスクリプトを使うGoogleアカウントを選択します。

(この画面が表示された場合のみ)左下の 詳細 をクリックします。

(この画面が表示された場合のみ)左下の プロジェクト名(安全ではないページ)に移動 をクリックします。

右下の 許可 をクリックします。

「承認が必要です」というダイアログが表示されますので、権限を確認 をクリックします。
* この部分の解説画像は、他の記事から流用しているため、実際のものと若干異なる場合があります。

このスクリプトを使うGoogleアカウントを選択します。

(この画面が表示された場合のみ)左下の 詳細 をクリックします。

(この画面が表示された場合のみ)左下の プロジェクト名(安全ではないページ)に移動 をクリックします。

右下の 許可 をクリックします。


実行ログに「実行完了」が表示されれば、予定の取得は成功です。
スプレッドシートの画面で、カレンダーの予定が取得できていることを確認してください。

その中から、削除したい予定だけを残してください。

サンプル予定1、2、9、10だけをカレンダーから削除したい場合、この画像のようになる。
続いて、指定した予定をカレンダーから一括削除します。
スクリプトエディタに戻り、deleteSpecifiedEvents関数を選択し、▷実行してください。

実行ログに、削除したカレンダーの予定が表示されます。
「実行完了」のログが表示されれば、指定した予定がすべて削除されているはずです。カレンダーの画面で確認してみてください。


コメント
はじめまして。こちらのスクリプトを使用させていただき、
予定のイベントを選択しての一括削除を試みております。
イベント抽出まではできましたが、削除実行の際に、
エラーが出て進まなくなってしまい困っております。
お助けいただけないでしょうか。
消したデータは、CSVで一括登録した暦のデータで、
データIDが(例)CSVConvert310e96ae24d0b052fcb9588ea664588aという形で表記されており、
他のでは226ojodadts4141ot79c0s3s9c@google.comなどとなっており、@google.comがないからではないかと推測しております。
私も試してみたところ、ご質問のとおりでした。
スクリプトを修正し、CSVからインポートした予定でも削除成功するようになりました。
この記事に掲載しているスクリプトも修正済ですので、再度お試しいただければと思います。
以下はメモです。
・CSVからインポートした予定は、getIdメソッドで取得したIDが「CSVConvert……」という形式になる
・その形式のIDでは、getEventByIdメソッドでイベントを取得できない
・旧スクリプトではgetEventByIdでイベントを取得して削除していた、これを変更し、対象期間の全イベントを取得し、getIdメソッドで取得したIDが削除対象のID(スプレッドシート上のID)と一致した場合に削除するようにした。