VBA 单元格内容存为txt文本文件

2022-05-29  本文已影响0人  JamesT
Sub 单元格内容保存为txt文件()
myPath = ThisWorkbook.Path & "\txt\"

'*********************用ADODB.STREAM进行写入UTF-8文本******************************
For i = 2 To 50
    Set OBJSTREAM = CreateObject("ADODB.Stream")
    With OBJSTREAM
        .Open
        .Position = 0
        .Charset = "UTF-8"
        StrText = Cells(i, "B").Value       '单元格内容
        .writeText StrText                  '写入单元格内容
        .SaveToFile myPath & Cells(i, "A").Value & ".html", 2   '存为html或者txt文件
        .Close
    End With
    Set OBJSTREAM = Nothing
Next
End Sub
上一篇 下一篇

猜你喜欢

热点阅读