Solved

VBA code gives error 91

Posted on 2016-09-02
10
47 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 46

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 46

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 46

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 46

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 46

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
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…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

910 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

23 Experts available now in Live!

Get 1:1 Help Now