Last active
September 19, 2025 10:52
-
-
Save silver-mixer/ce8327eac7b0ae14fb8cea0c093f331c to your computer and use it in GitHub Desktop.
アクティブなセルにYYYY/MMで日付が入力されていた場合、入力された月の月末日に置換するLibreOffice Basicマクロ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| REM ***** BASIC ***** | |
| Sub GetLastDayOfTheMonth | |
| ' 正規表現関連の関数に必要なライブラリ | |
| GlobalScope.BasicLibraries.loadLibrary("ScriptForge") | |
| Dim targetText As String | |
| Dim year, month As Integer | |
| targetText = ThisComponent.CurrentSelection.String | |
| 'targetText = InputBox("月末日を取得したい年月を指定してください。(YYYY/MMで指定)") | |
| If IsRegex(targetText, "\d{4}/\d{1,2}") Then | |
| ' 年部分を取得 | |
| year = CInt(FindRegex(targetText, "\d{4}(?=/\d)")) | |
| ' 月部分を取得 | |
| month = CInt(FindRegex(targetText, "(?<=\d{4}/)\d{1,2}")) | |
| ' 月が12月の場合、年をインクリメント | |
| If month = 12 Then | |
| year = year + 1 | |
| End If | |
| ' 翌月を計算 | |
| month = month Mod 12 + 1 | |
| ' 指定された翌月の1日から1日引いた日付をセルに設定 | |
| ThisComponent.CurrentSelection.Value = DateAdd("d", -1, DateValue(year & "-" & month & "-1")) | |
| End If | |
| End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment