• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 98
  • Last Modified:

VBA code gives error 91

Hi, this question is related to a code provided by Excel Tables Hero Zack.

https://www.experts-exchange.com/questions/28380445/Count-Items-on-Fluent-Ribbon-in-MS-Word-Excel-using-VBA.html#a39907831

when i run the code in the file uploaded there, the debugger stops at line For
Each oNode In oNodeList.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes

Open in new window

 runtime error 91 Object Variable or With Block Variable not set

the file Test.docm exists,  the XML object library in references already there. i cannot figure out what it causing this.

thanks.
0
Flora
Asked:
Flora
  • 5
  • 4
1 Solution
 
crystal (strive4peace) - Microsoft MVP, AccessRemote Training and ProgrammingCommented:
on the thread you referenced, the last comment (DrTribos) was to add statements to skip errors and he gives an example. Perhaps there is no object there.
0
 
Martin LissOlder than dirtCommented:
Do you have something like this in the sub?

Dim oNode As IXMLDOMNode
Dim oNodeList As IXMLDOMNodeList
0
 
FloraAuthor Commented:
Hi Martin,

i this is the whole UDF

Public Function CountItemsInXML(ByVal sXML As String) As Long
    Dim oNode                   As MSXML2.IXMLDOMNode
    Dim oNodeChild              As MSXML2.IXMLDOMNode
    Dim oNodeList               As MSXML2.IXMLDOMNodeList
    Dim oXMLDoc                 As MSXML2.DOMDocument
    Dim iAttribute              As Long
    Dim iCount                  As Long
    Set oXMLDoc = New MSXML2.DOMDocument
    oXMLDoc.loadXML sXML
    Set oNodeList = oXMLDoc.SelectNodes("/customUI")
    'Nodes: CustomUI/Ribbon/Tabs/Tab/Groups
    For Each oNode In oNodeList.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes.Item(0).ChildNodes
        For Each oNodeChild In oNode.ChildNodes
            If oNodeChild.Attributes.Length > 1 Then
                iCount = iCount + 1
            End If
        Next
    Next
    CountItemsInXML = iCount
End Function

Open in new window

0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Martin LissOlder than dirtCommented:
Put a breakpoint on line 10 and in the Immediate window type ?onodelist.count and press return. What do you get?


Can you post the XML file?
0
 
FloraAuthor Commented:
thanks Martin, here it is attached the whole file.
EditOpenXML.xlsm
0
 
Martin LissOlder than dirtCommented:
I'm sorry but what I was asking for was the XML input file. Also the workbook you attached doesn't contain the CountItemsInXML UDF.
0
 
FloraAuthor Commented:
sorry Martin, here is the file.

please remove .zip from it.

i  could not upload the file ext  .docm so i zipped it.
Test.docm.zip
0
 
Martin LissOlder than dirtCommented:
The file you uploaded is not an xml file but rather just a one-page document with the single line "1111111".

You also didn't respond to my stating that the workbook you attached doesn't contain the CountItemsInXML UDF. What should I do about that?
0
 
FloraAuthor Commented:
thanks Martin. i have found the problem by putting breakpoints as you suggestion.
0
 
Martin LissOlder than dirtCommented:
You're welcome and I'm glad I was able to help.

In my profile you'll find links to some articles I've written that may interest you.

Marty - Microsoft MVP 2009 to 2016
              Experts Exchange MVE 2015
              Experts Exchange Top Expert Visual Basic Classic 2012 to 2015
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now