在VBA中将XML文件转换为stringvariables

我期待在Excel VBA中将XML文件的内容转换为stringvariables,以便我可以search文件中的特定string。

但是我不知道如何执行从XML文件到stringvariables的初始转换。 到目前为止,我所能做的就是加载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 

到目前为止,这一切都返回“真”,表示文件正在加载。

我将如何将XML文件转换为string?

这是一个方法来做你所问:

 Dim FSO As Object : Set FSO = CreateObject("Scripting.FileSystemObject") Dim strXml As String strXml = FSO.OpenTextFile("C:\myfile.xml").ReadAll 

这是一个函数,我目前正在使用我的旧应用程序之一,将文件转换为string。

 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/的代码的一部分