vba用一个/生成txt文件替换两个引号

时间:2017-04-05 15:06:18

标签: excel vba excel-vba excel-2013 string-concatenation

我创建了一个宏来生成包含excel中每一行数据的txt文件。我有“(引号)

的问题

以下是VBA产生问题的一行:

wsTemp.Cells(6, 1).Value = "The ""Number"" is " & wsSource.Cells(r, 3).Value

我需要这个:The "Number" is MYNUMBER

而不是我得到这个:" The ""Number"" is" MYNUMBER

这也不起作用:

wsTemp.Cells(6, 1).Value = "The" & Chr(34) & "Number"" is " & Chr(34) & wsSource.Cells(r, 3).Val(获得相同的输出)

我尝试用""替换Chr(34)(没有用)

我也在最后尝试了替换功能:

wsTemp.Cells(6, 1).Value = Replace(wsTemp.Cells(6, 1).Value, """", """)(没有用)和 wsTemp.Cells(6, 1).Value = Replace(wsTemp.Cells(6, 1).Value, """", Chr(34))(效果不佳)

Replace()适用于其他Chr()Replace(wsTemp.Cells(6, 1).Value, """", "")但不适用于Chr(34)

无论如何,我需要一个“而不是两个”或其他任何东西

我将生成的文件保存为xlCurrentPlatformText和.txt,我也尝试过其他格式

另外,当我手动将excel中的相同文本保存为txt

时,我注意到了这一点

我几乎尝试了一切,没有任何效果

我正在使用Win 7和Excel 2013

2 个答案:

答案 0 :(得分:0)

尝试将其作为其中之一,

With wsTemp.Cells(6, 1)
    .Value = Format(wsSource.Cells(r, 3).Value2, "\T\h\e \""\N\u\m\b\e\r\"" \i\s 0")
    .Offset(1, 0) = "The ""Number"" is " & wsSource.Cells(r, 3).Value2
    .Offset(2, 0) = "The " & Chr(34) & "Number" & Chr(34) & " is " & wsSource.Cells(r, 3).Value2
End With

答案 1 :(得分:0)

所以我用@xidgel suddgested做了,用FindAndReplaceText(放屁)

我将所有"替换为$$$$

我创建了一个文件replace.bat

fart -r "MYLOCATION*.txt" $$$$ \"

并在vba宏的末尾添加了shell execute命令

Call Shell("C:\LOCATION\replace.bat", vbNormalFocus)
相关问题