0

ワークブックがローカル テキスト ファイルに保存されるボタン クリックのコードがあります。

ワークブックには以下の情報が含まれています。

致命的; insert into ifparam values(3498,'TAT_UNALLOCTRADESREC','STRING','IF(STRING(C5)=STRING("TCE - 外部ヘッジ"),STRING("E"),IF(STRING(C5)=STRING(" TCE - 内部ヘッジ"),STRING("I"),STRING(C5)))');

ただし、出力は CRITICAL になります。

insert into ifparam values(3498,'TAT_UNALLOCTRADESREC','STRING','IF(STRING(C5)=STRING(""TCE - External Hedge""),STRING(""E""),IF(STRING(C5)=STRING(""TCE - Internal Hedge""),STRING(""I""),STRING(C5)))'); 

問題は、出力に " we are gets "" がある場所です。ワークブックにあるように、これを取得するのを手伝ってくれる人はいますか? "" の代わりに単一二重引用符 "

コードの変更が必要な場合は提案してください。使用コード:

Private Sub CommandButton1_Click()
    Dim xlBook As Workbook, xlSheet As Worksheet
    Dim strOutputFileName As String
    Dim n As Long, i As Long, j As Long
    Dim MyData As String, strData() As String, MyArray() As String
    Dim strPath As String

    strPath = ActiveWorkbook.Path '<~~ \\plyalnppd3sm\d$\Temp\Arun\TAT\

    ThisWorkbook.SaveCopyAs strPath & "\Temp.xls"

    Set xlBook = Workbooks.Open(strPath & "\Temp.xls")

    For Each xlSheet In xlBook.Worksheets
        If xlSheet.Name <> "User_provided_data" Then
            strOutputFileName = strPath & "\" & xlSheet.Name & ".zup"
            xlSheet.SaveAs Filename:=strOutputFileName, FileFormat:=xlTextMSDOS



    n = n + 1

            ReDim Preserve MyArray(n)
            MyArray(n) = strOutputFileName
            Debug.Print strOutputFileName
        End If
    Next

    xlBook.Close SaveChanges:=False

    Kill strPath & "\Temp.xls"

    For i = 1 To UBound(MyArray)
        '~~> open the files in One go and store them in an array
        Open MyArray(i) For Binary As #1
        MyData = Space$(LOF(1))
        Get #1, , MyData
        Close #1
        strData() = Split(MyData, vbCrLf)

        '~~> Write to the text file
        Open MyArray(i) For Output As #1

        '~~> Loop through the array and check if the start and end has "
        '~~> And if it does then ignore those and write to the text file
        For j = LBound(strData) To UBound(strData)
            If Left(strData(j), 1) = """" And Right(strData(j), 1) = """" Then
                strData(j) = Mid(strData(j), 2, Len(strData(j)) - 2)
            End If
            Print #1, strData(j)
        Next j
        Close #1
    Next i
End Sub
4

1 に答える 1

0

コードをあまり見ない最も簡単な解決策 -strData(j)テキスト ファイルに出力する前に、次の行を追加します。

strData(j) = Replace(strData(j), """""", """")

もっと良い方法があると思いますが、これは非常にシンプルで、迅速で汚い修正です!

于 2013-03-01T15:25:44.727 に答える