From 35bdc1479b4e7c49d66b99cf407dd7d7be2c89b4 Mon Sep 17 00:00:00 2001 From: updsv7 Date: Mon, 13 Apr 2026 19:02:04 +0900 Subject: [PATCH] Merge ReadCSVFileWithUtf8 into ReadCSVFile with charset parameter --- vba_code_common.bas | 22 ++++++++++++++++++++++ vba_code_kotsu_master.bas | 2 +- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/vba_code_common.bas b/vba_code_common.bas index 337e86d..88f18f8 100644 --- a/vba_code_common.bas +++ b/vba_code_common.bas @@ -151,3 +151,25 @@ Function ReadCSVFileWithUtf8(ByVal filePath As String) As Variant ReadCSVFileWithUtf8 = Split(textContent, vbLf) End Function + +Function ReadCSVFile(ByVal filePath As String, Optional ByVal charset As String = "shift_jis") As Variant + If filePath = "" Then + ReadCSVFile = Array() + Exit Function + End If + + Dim stream As Object + Dim textContent As String + + Set stream = CreateObject("ADODB.Stream") + With stream + .Type = 2 + .Charset = charset + .Open + .LoadFromFile filePath + textContent = .ReadText + .Close + End With + + ReadCSVFile = Split(textContent, vbLf) +End Function diff --git a/vba_code_kotsu_master.bas b/vba_code_kotsu_master.bas index daede6e..9d78e19 100644 --- a/vba_code_kotsu_master.bas +++ b/vba_code_kotsu_master.bas @@ -19,7 +19,7 @@ Sub Z1_ImportMasterDetailData() If filePath = "" Then Exit Sub ' Step 2: Read CSV - lines = ReadCSVFileWithUtf8(filePath) + lines = ReadCSVFile(filePath, "utf-8") ' Step 3: Validate column count If Not ValidateCSVColumnCount(lines, 7) Then Exit Sub