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