Solved

VBA code gives error 91

Posted on 2016-09-02
10
38 Views
Last Modified: 2016-09-09
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
Comment
Question by:Flora
  • 5
  • 4
10 Comments
 
LVL 19
ID: 41782026
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41782149
Do you have something like this in the sub?

Dim oNode As IXMLDOMNode
Dim oNodeList As IXMLDOMNodeList
0
 
LVL 5

Author Comment

by:Flora
ID: 41783264
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
 
LVL 45

Accepted Solution

by:
Martin Liss earned 500 total points
ID: 41783286
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
 
LVL 5

Author Comment

by:Flora
ID: 41789399
thanks Martin, here it is attached the whole file.
EditOpenXML.xlsm
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 45

Expert Comment

by:Martin Liss
ID: 41789599
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
 
LVL 5

Author Comment

by:Flora
ID: 41791259
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
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41791315
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
 
LVL 5

Author Closing Comment

by:Flora
ID: 41791326
thanks Martin. i have found the problem by putting breakpoints as you suggestion.
0
 
LVL 45

Expert Comment

by:Martin Liss
ID: 41791335
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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Introduction This Article is a follow-up to my Mappit! Addin Article (http://www.experts-exchange.com/A_2613.html), it was inspired by an email posting I made to EUSPRIG (http://www.eusprig.org/index.htm), I will briefly cover: 1) An overvie…
Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now