我正在开发一个宏,该宏将查找HTML文件中的EN文本并替换为FR文本。我已经写了下面的代码。我想替换";哮喘被驯服";用";《东方控制》;但在HTML文件中,它显示的输出是这样的";l�哮喘对照�le";。
注意:-我无法更改任何系统设置。
Sub replacetext()
Const ForReading = 1
Const ForWriting = 2
Dim strFileName, strOldText, RstrOldText, strNewText As String
strFileName = ##### HTML File Path #####
strOldText = "asthma tamed"
MsgBox (strOldText)
'RstrOldText = RemoveHTML(strOldText)
'MsgBox (RstrOldText)
strNewText = "l’asthmesous contrôle"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFileName, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, strOldText, strNewText)
Set objFile = objFSO.OpenTextFile(strFileName, ForWriting)
objFile.WriteLine strNewText
objFile.Close
MsgBox "Text Replaced !!!"
End Sub
Function RemoveHTML(text)
Dim regexObject As Object
Set regexObject = CreateObject("vbscript.regexp")
With regexObject
.Pattern = "<!*[^<>]*>"
.Global = True
.IgnoreCase = True
.MultiLine = True
.Format = "Unicode Text"
End With
RemoveHTML = regexObject.Replace(text, "")
End Function
您是否尝试在每个特殊字符之前添加\?使用ô;对于扬抑符,而只是"对于"或"?