|
-
June 24th, 2008, 08:31 AM
#1
Manipulating XML with VBA
I'm using Microsoft Visual Basic 6.3
I'm not sure if this is the right place to ask this question, but here it goes.
I'm going to make a small Word application which can manipulate a XML file
Code:
Private Sub ManipulateXLM()
Dim doc As MSXML2.DOMDocument
doc.Load ("C:\Documents and Settings\z3xld\Desktop\2Usecases.xml")
End Sub
It says:
runtime error '91':
Object variable or With block variable not set
Can anyone see what might be the problem?
-
June 24th, 2008, 08:54 AM
#2
Re: Manipulating XML with VBA
You need to SET a reference to MSXML first. Here are some VB6 samples:
Code:
Option Explicit
' These are both examples of Late Binding
Public Sub RunAccessMacro(strDB As String, strMacro As String)
'================================================================
'for late binding declare it As Object and use CreateObject() function
Dim AccessDB As Object
Set AccessDB = CreateObject("Access.Application")
With AccessDB
.OpenCurrentDatabase strDB
.DoCmd.RunMacro strMacro, 1
'.Visible = True 'you decide
.CloseCurrentDatabase
End With
Set AccessDB = Nothing
End Sub
Public Sub ExcelMacro()
Dim excl As Object
Dim wrbk As Object
Set excl = CreateObject("Excel.Application")
excl.DisplayAlerts = False
Set wrbk = excl.Workbooks.Open("myfile", , True, , "mypassword")
excl.Run "MacroName", "arg1", "arg2"
End Sub
It should work in VBA, but you might have to use VARIANT instead of OBJECT.
-
June 24th, 2008, 09:23 AM
#3
Re: Manipulating XML with VBA
Thanks, but could you maybe edit my example? I haven't really coded VBA before, so I'm not used to the syntax.
is it something like this?
Code:
Private Sub ManipulateXLM()
Dim doc As MSXML2.DOMDocument
Set doc = Load("C:\Documents and Settings\z3xld\Desktop\2Usecases.xml")
With doc
//Do stuff
End With
End Sub
It won't work though
-
June 24th, 2008, 09:29 AM
#4
Re: Manipulating XML with VBA
Oh got it now I think Thanks a lot
Code:
Private Sub ManipulateXLM()
Dim doc As New MSXML2.DOMDocument
doc.Load("C:\Documents and Settings\z3xld\Desktop\2Usecases.xml")
With doc
//Do stuff
End With
End Sub
Or
Code:
Private Sub ManipulateXLM()
Dim doc As MSXML2.DOMDocument
Set doc = new MSXML2.DOMDocument
doc.Load("C:\Documents and Settings\z3xld\Desktop\2Usecases.xml")
With doc
//Do stuff
End With
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|