'+++++++++++++++++++++++++++++++++++++
' Get output object
' Return output object
' eg.
' Dim wo as object
' Call GetWriteObject(wo)
'+++++++++++++++++++++++++++++++++++++
Function GetWriteObject(ByRef TextStream As Object)
Set TextStream = CreateObject("ADODB.Stream")
With TextStream
.Mode = 3
.Open
.CharSet = "UTF-8"
.Position = TextStream.Size
End With
End Function
'+++++++++++++++++++++++++++++++++++++
' Write content to object
' eg.
' Dim wo as object
' Call GetWriteObject(wo)
' strA = "This is sample."
' writeContent(strA, wo)
'+++++++++++++++++++++++++++++++++++++
Function WriteContent(ByVal strContent As String, ByRef TextStream As Object)
TextStream.WriteText strContent
End Function
'+++++++++++++++++++++++++++++++++++++
' Write content to file
' eg.
' Dim wo as object
' Call GetWriteObject(wo)
' strA = "This is sample."
' writeContent(strA, wo)
' WriteFile(strPath, wo)
'+++++++++++++++++++++++++++++++++++++
Function WriteFile(ByVal strFilename As String, ByRef TextStream As Object, Optional ByVal adSaveCreateOverWrite As String = "2")
TextStream.SaveToFile strFilename, adSaveCreateOverWrite
TextStream.Close
End Function
读取成UTF-8,并以UTF-8编码写入文本文件
本文介绍了一种使用VBA进行文件读写的方法,包括创建流对象、写入内容到对象及保存对象到文件的过程。该方法适用于需要通过VBA自动化进行文本文件处理的场景。

4372

被折叠的 条评论
为什么被折叠?



