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

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

你可能感兴趣的:(VBA 单元格内容存为txt文本文件)