| 
    
     |  | おはようございます。 
 出かけてしまうのでヒントになるコードだけ・・・。
 
 新規ブックの標準モジュールに
 '==============================================
 Sub main()
 Dim s As String
 s = "ああああああああああああああああ"
 MsgBox myreplace(s)
 s = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
 MsgBox myreplace(s)
 s = "CREATE TABLE ""○○○○"" ("
 MsgBox myreplace(s)
 s = "いいいいいいいいいいいいいいいいい"
 MsgBox myreplace(s)
 End Sub
 '=================================================================
 Function myreplace(mystr As Variant) As Variant
 Dim matches As Object
 Dim mm As Object
 myreplace = mystr
 With CreateObject("VBScript.RegExp")
 .Pattern = "^CREATE TABLE "".+"""
 .IgnoreCase = True
 .Global = True
 Set matches = .Execute(mystr)
 For Each mm In matches
 .Pattern = mm.Value
 myreplace = .Replace(mystr, Mid(mm.Value, 1, Len(mm.Value) - 1) & "P" & """")
 Next
 End With
 End Function
 
 
 上記のmainを実行してみてください。
 結果から、参考にしてください
 
 
 |  |