\test\の中にCSVのファイルが複数あります
複数のファイルは連続でマクロ実行できること
データは文字列でA列に1行目からあります
このデータの中に”(ダブルコーテーション)が含まれている文字があります
このデータの中から”(ダブルコーテーション)だけを取るマクロをおねがいします
"abcd"
abcd
"bbb"."cccc""
bbbb.cccc
以下のマクロをお試しください。
Option Explicit '1行処理 Function convRow(buf As String, ln As Long, path As String, fname As String) As String Dim items() As Variant Dim sour As String Dim i As Integer 'ダブルクォーテーション削除 Set re = CreateObject("VBScript.RegExp") pat = """" With re .Pattern = pat .IgnoreCase = True .Global = True End With buf = re.Replace(buf, "") Set re = Nothing convRow = buf End Function '1ファイル処理 Sub convFile(path As String, fname As String) Dim ln As Long Dim buf As String Dim fname1 As String, fname2 As String fname1 = path & fname fname2 = path & fname & ".$$$" Open fname1 For Input As #1 Open fname2 For Output As #2 ln = 1 Do Until EOF(1) Line Input #1, buf buf = convRow(buf, ln, path, fname) If (buf <> "") Then Print #2, buf ln = ln + 1 Loop Close #1 Close #2 Kill fname1 'オリジナル・ファイル削除 Name fname2 As fname1 End Sub 'ファイル探索+処理実行 Sub hogeConv(path As String, ext As String) Dim fcol As Object, re As Object Dim flist As Variant, remat As Variant Dim pat As String 'サブディレクトリ探索 Set fcol = CreateObject("Scripting.FileSystemObject").GetFolder(path).SubFolders For Each flist In fcol Call hogeConv(path & flist.Name & "/", ext) Next flist Set fcol = Nothing '処理対象ファイル探索+処理実行 Set fcol = CreateObject("Scripting.FileSystemObject").GetFolder(path).Files Set re = CreateObject("VBScript.RegExp") pat = "\." & ext & "$" With re .Pattern = pat .IgnoreCase = True .Global = True For Each flist In fcol Set remat = .Execute(flist.Name) If remat.Count > 0 Then Call convFile(path, flist.Name) Next flist End With Set re = Nothing Set fcol = Nothing End Sub Sub main() Call hogeConv("C:/test/", "csv") End Sub