我希望将XML文件的内容转换为excel VBA中的String变量,以便我可以在文件中搜索特定的字符串。
但是我不知道如何从XML文件到String变量进行初始转换。到目前为止,我所能做的就是加载XML文档,从那里我就被卡住了。
Public Function DetermineSpecifiedChange(ByVal vstrInputGBOMPath As String, ByVal vstrInputPDPPath As String)
Dim strPDPString As String
Dim strGBOMString As String
Dim xmlGBOM As New DOMDocument60
Dim xmlPDP As New DOMDocument60
strPDPString = xmlPDP.Load(vstrInputPDPPath)
End Function
到目前为止,所有返回的都是“True”,表示正在加载文件。
我如何将XML文件转换为字符串?
答案 0 :(得分:3)
这是一种做你要求的方法:
Dim FSO As Object : Set FSO = CreateObject("Scripting.FileSystemObject")
Dim strXml As String
strXml = FSO.OpenTextFile("C:\myfile.xml").ReadAll
答案 1 :(得分:1)
这是我目前在我的一个旧应用程序中使用的函数,用于将文件转换为字符串。
Private Function FileToText(fullFilePath as String) as string
Dim nFile As Integer
Dim baBuffer() As Byte
Dim sPostData As String
nFile = FreeFile
Open fullFilePath For Binary Access Read As nFile
If LOF(nFile) > 0 Then
ReDim baBuffer(0 To LOF(nFile) - 1) As Byte
Get nFile, , baBuffer
sPostData = StrConv(baBuffer, vbUnicode)
End If
Close nFile FileToText = sPostData
FileToText = sPostData
这是http://wqweto.wordpress.com/2011/07/12/vb6-using-wininet-to-post-binary-file/
代码的一部分