I am trying to execute javascript on an IE 11 web page that contains frames and I am using VBA to execute the javascript. This is my first attempt so I am probably making some rookie mistakes. The action I am trying to automate is pressing a "+" sign on a folder to expand it. I have seen a lot of discussion on this topic and I have tried to include what I think is relevant to my code. But after many attempts, I still cannot get it to work. The VBA code I am trying to get to work is as follows. Each call below to execScript has been an attempt to execute the javascript. The VBA error message that I received is placed as a comment before each call. Thanks in advance for any help that you can offer.
Dim doc As MSHTML.IHTMLDocument
Dim Frames As MSHTML.IHTMLFramesCollection2
Dim Window As MSHTML.IHTMLWindow2
ie.Navigate "URL of my web page"
Set doc = ie.Document
' Error: Method 'frames' of object JScriptTypeInfo failed.
Call ie.Document.Frames(0).execScript("populateNode(document.getElementById('treeViewRootNode_Home_0_children'),treeView_Data,document.getElementById('treeViewRootNode_Home_0'),'treeViewRootNode_Home_0');", "JavaScript")
' Error: Could not complete the operation due to error 80020101.
Call ie.Document.Frames.Item(0).execScript("populateNode(document.getElementById('treeViewRootNode_Home_0_children'),treeView_Data,document.getElementById('treeViewRootNode_Home_0'),'treeViewRootNode_Home_0');", "JavaScript")
' Error: Method 'frames' of object JScriptTypeInfo failed.
Call ie.Document.Frames("navigationBodyFrame").execScript("populateNode(document.getElementById('treeViewRootNode_Home_0_children'),treeView_Data,document.getElementById('treeViewRootNode_Home_0'),'treeViewRootNode_Home_0');", "JavaScript")
Here is a portion of the HTML for the frame that I was able to grab with Firebug:
<span id="treeViewRootNode_children" style="display:block">
<table cellspacing="0" cellpadding="0" border="0">
<span id="treeViewRootNode_Home_children" style="display:block">
<table cellspacing="0" cellpadding="0" border="0">
<span id="treeViewRootNode_Home_MyFolders_children" style="display:none">
<table cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>
<td>
<span id="treeViewRootNode_Home_0_spare"></span>
<span id="treeViewRootNode_Home_0_hidden" style="display: none"></span>
<a id="treeViewRootNode_Home_0" href="javascript:populateNode(document.getElementById('treeViewRootNode_Home_0_children'),treeView_Data,document.getElementById('treeViewRootNode_Home_0'),'treeViewRootNode_Home_0');">
<img id="treeViewRootNode_Home_0_lineImg" src="LineImages/lplus.gif" border="0">
</a>
</td>
<td nowrap="true">
</tr>
</tbody>
</table>
<span id="treeViewRootNode_Home_0_children" style="display:none"></span>
ie.Document.Frames(0).contentWindow.execScript "alert('ok')"