代码如下:
一,前期绑定:
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