从excel复制时,xml文件更改其字符

时间:2017-02-06 17:58:06

标签: xml vba excel-vba character-encoding excel

我正在编写一个excel VBA程序,它将XML文件作为文本读取,并通过在excel中搜索来替换文本。

示例XML:

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<figlist>
  <figgroup name="Circuit Diagram">
    <category  id="A">
      <name>A GENERAL INFORMATION</name>
      <subcategory name="GI  GENERAL INFORMATION">
        <fig id="jtawa5495gb">
          <name>CONSULT CHECKING SYSTEM</name>
          <svgfile>jtawa5495gb.svg</svgfile>
        </fig>
      </subcategory>
    </category >

在此XML中,我想替换文本,例如Circuit Diagram

在Excel中,我有这样的布局:

Column A                 Column B
"Circuit Diagram"        Schéma du circuit

B栏将是法语。

问题,在替换Schéma du circuit时,不支持字符é。我该如何更改?

这是我的代码:

Set fso = CreateObject("Scripting.FileSystemObject")
      For Each fil In fso.GetFolder(strpath2).Files

        If fil.Name = "figlist.xml" Then
         Set txt = fil.OpenAsTextStream(1)


              str_change = txt.ReadALL

             OutBook.Activate
             Lines = OutBook.ActiveSheet.Range("A65536").End(xlUp).Row

                For i = 1 To Lines
                 wer = Outbook1.ActiveSheet.Cells(i, 1).Value
              wer2 = Outbook1.ActiveSheet.Cells(i, 2).Value
                str_change = Replace(str_change, wer, wer2, vbTextCompare)

             Next i

         With fil.OpenAsTextStream(2)
        .Write str_change
        .Close
         End With

        End If
    Next fil

0 个答案:

没有答案