其他分享
首页 > 其他分享> > VBA转换txt文件编码

VBA转换txt文件编码

作者:互联网

代码如下:

一,前期绑定:

Sub 转换txt文件编码()
   Dim stm As New ADODB.Stream
   Dim str As String
   Dim ins As String
   ins = ThisWorkbook.Path & "\数据.txt"
   With stm
      .Charset = "GB2312"
      .Open
      .LoadFromFile ins
      str = .ReadText
      .Close
      .Charset = "utf-8"
      .Open
      .WriteText str
      .SaveToFile ins, adSaveCreateOverWrite
      .Close
   End With
   Set stm = Nothing
End Sub

二,后期绑定:

Sub 转换txt文件编码()
   Dim stm As Object
   Set stm = CreateObject("ADODB.Stream")
   Dim str As String
   Dim ins As String
   ins = ThisWorkbook.Path & "\数据.txt"
   With stm
      .Charset = "GB2312"
      .Open
      .LoadFromFile ins
      str = .ReadText
      .Close
      .Charset = "utf-8"
      .Open
      .WriteText str
      .SaveToFile ins, 2
      .Close
   End With
   Set stm = Nothing
End Sub

  

 

标签:编码,VBA,End,Dim,stm,ins,str,txt
来源: https://www.cnblogs.com/mrlajie/p/15569592.html