2

Here is the html for the pop up box:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!-- BEGIN /layouts/new_empty_layout.jsp -->











<html>
 <head>
  <title>SERFF - System for Electronic Rate and Form Filing</title>
  <!--    Copyright 2016 National Association of Insurance Commissioners -->


<link rel="stylesheet" type="text/css" href="/styles/serff-core.css"/>
<link rel="stylesheet" type="text/css" href="/styles/core-header.css"/>
<link rel="stylesheet" type="text/css" href="/styles/core-content.css"/>
<link rel="stylesheet" type="text/css" href="/scripts/jquery-ui-css/custom-theme/jquery-ui-1.10.4.custom.css"/>
  




<script type="text/javascript">
 var staticUrlPath = '/';
 var appUrlPath = '/serff/';
</script>
<script type="text/javascript" src="/scripts/jquery-1.12.1.min.js"></script>
<script type="text/javascript" src="/scripts/jquery.textarea.pack.js"></script>
<script type="text/javascript" src="/scripts/jquery-ui-1.10.0.min.js"></script>
<script type="text/javascript" src="/scripts/datepicker.js"></script>
<script type="text/javascript" src="/scripts/default_layout.js"></script>





<script>
 // custom SERFF dimensions:
 // dimension1 = SERFF User Type custom GA dimension

 var analyticsEnabled = true;
 
 // insert the analytics script and initialize the Google Analytics "ga" object
 if(analyticsEnabled){
  var currentScript = document.currentScript || (function() {
   var scripts = document.getElementsByTagName('script');
    return scripts[scripts.length - 1];
      })();
  
  var gaScript = document.createElement('script');
  gaScript.async = true;
  gaScript.src = '/public/lib/ga/analytics.js';
  document.getElementsByTagName("head")[0].insertBefore(gaScript, currentScript);
  
  var ga = window.ga = window.ga || function(){(window.ga.q = window.ga.q || []).push(arguments)};
  window.ga.l = +new Date();
  window.GoogleAnalyticsObject = 'ga';
  ga('create', 'UA-5133885-7', 'auto');
 }
 
 function analyticsPageView()
 {  
  doSendAnalytics(function() {
   ga('send', 'pageview');
  });
 }

 function analyticsPageViewWithUserType()
 { doSendAnalytics(function() { 
   ga('send', 'pageview', {
    'dimension1' : getUserType()
   });
  });
 }

 function analyticsEvent(eventCategory, eventAction, callback){
  if(callback){
   doSendAnalytics(function() {
    ga('send', 'event', eventCategory, eventAction, {'hitCallback': callback});
   });
  } else {
   doSendAnalytics(function() {
    ga('send', 'event', eventCategory, eventAction);
   });
  }  
 }

 function analyticsEventWithUserType(eventCategory, eventAction, callback){
  if(callback){
   doSendAnalytics(function() {
    ga('send', 'event', eventCategory, eventAction, {'hitCallback': callback, 'dimension1' : getUserType()});
   });
  } else {
   doSendAnalytics(function() {
    ga('send', 'event', eventCategory, eventAction, {'dimension1' : getUserType()});
   });
  }
 }

 function getUserType(){
  var userType = 'I';
     if(userType == 'S'){
         userType = 'State User';
     } else if(userType == 'I') {
   userType = 'Industry User';
     } else if (userType == 'N') {
   userType = 'NAIC Admin User';
  }
     return userType;
 }

 // only send a message to GA if enabled in the INI file
 function doSendAnalytics(method){  
  if(analyticsEnabled){
   method();
  }
 }
 

</script>
  
  <link rel="stylesheet" type="text/css" href="/styles/forms2.css"/>
  <!-- BEGIN /layouts/iefixes.jsp -->












 

 

 

 


<!-- END /layouts/iefixes.jsp -->

  

 </head>
 
 <body>
  <div id="content">
   <div id="main" style="background: none;">
    <!--    Copyright 2014 National Association of Insurance Commissioners -->
<!-- BEGIN /filing/ -->








<html>
<head>
<title>SERFF - System for Electronic Rate and Form Filing</title>
<link rel="stylesheet" type="text/css"
 href="/styles/serff-core.css" />
<link rel="stylesheet" type="text/css"
 href="/styles/core-header.css" />
<link rel="stylesheet" type="text/css"
 href="/styles/core-content.css" />
<link rel="stylesheet" type="text/css"
 href="/styles/forms2.css" />
<!-- BEGIN /layouts/iefixes.jsp -->












 

 

 

 


<!-- END /layouts/iefixes.jsp -->


 <script language="javascript">
  var uploadSubmitted = false;
  $( document ).ready(function() {
   $( 'form' ).submit(function( event ) {
    if (uploadSubmitted) {
     alert( "You have already performed this action.  Please wait for the page to refresh." );
     event.preventDefault();
    } else {
     uploadSubmitted = true;
    }
   });
  });
 
  var skipcycle = false;
  function updateAttachments() {
   
   var groupId = window.opener.selectedAttachmentGroup;
   if (uploadForm.groupId.value == null || uploadForm.groupId.value ==''){
    uploadForm.groupId.value = groupId;
   }
   var index = window.opener.selectedIndex;
   if (uploadForm.index.value == null || uploadForm.index.value ==''){
    uploadForm.index.value = index;
   }
   
  }
  
  function focusOnMe(){
  if (!skipcycle){
  window.focus(); 
  }
  mytimer = setTimeout('focusOnMe()', 500);
  }      
  
 </script>
</head>
<body onload = "mytimer = setTimeout('focusOnMe()', 500);updateAttachments();">
<h2>SERFF File Attachment Upload</h2>
<div class="documentArea">
 <form name="uploadForm" method="POST" action="/serff/uploadFileAttachment.do" class="styled" enctype="multipart/form-data" id="uploadForm">
  <input type="hidden" name="groupId" />
  <input type="hidden" name="index" />
  
  
   
    
   
   
  
  <input type="hidden" name="attachmentType" value="0">
 
  <div class="uploadWarning" style="width:325px">
   Attachments larger than 3MB or Microsoft Word(tm) documents cannot be uploaded to SERFF.
  </div>
  
   
  <div class="fieldgroup">File 1:&nbsp;&nbsp; <input type="file" name="contentIndexed[0]" value="" onfocus="skipcycle=true" class="inputFile"></div>
 
  <div class="fieldgroup">File 2:&nbsp;&nbsp; <input type="file" name="contentIndexed[1]" value="" onfocus="skipcycle=true" class="inputFile"><br />
  </div>
 
  <div class="fieldgroup">File 3:&nbsp;&nbsp; <input type="file" name="contentIndexed[2]" value="" onfocus="skipcycle=true" class="inputFile"><br />
  </div>
 
  <div class="fieldgroup">File 4:&nbsp;&nbsp; <input type="file" name="contentIndexed[3]" value="" onfocus="skipcycle=true" class="inputFile"><br />
  </div>
  <div class="fieldgroup">File 5:&nbsp;&nbsp; <input type="file" name="contentIndexed[4]" value="" onfocus="skipcycle=true" class="inputFile"><br />
  </div>
  <br />
  <div class="actionButtons">
   <input type="submit" value="Upload" class="inputSubmit">
   <input type="button" class="inputButton" onclick="window.close();" value="Cancel" />
  </div>
 </form>
</div>
</body>
</html>
<!-- END /filing/fileUpload.jsp -->

   </div> <!-- end main div --> 
  </div> <!-- end content div -->
 </body>
</html>
<!-- END /layouts/new_empty_layout.jsp -->

I am trying to get the upload file dialog box to appear by using vba to "click" on one of the browse buttons. The problem is that vba will not let me find the input tags within the uploadForm.

My own code for this:

Set uploadForm = ieUpload.document.getElementById("uploadForm")
For Each inputTag In uploadForm.getElementsByTagName("input")
If inputTag.Name = "contentIndexed[0]" Then inputTag.Click
Next inputTag

Vba raises an "Object variable or with block variable not set" error on the for loop.

Seraphim
  • 171
  • 1
  • 12
  • I have updated the question. I am aiming to open the file dialog box and use sendkeys (shudder) to input the filename. I have tried using send keys to tab through the window and select the browse button but that also has failed to work properly. – Seraphim Apr 18 '17 at 18:08

1 Answers1

1

Edited after discussion in chat

It turned out the document had not finished loading. Checking ieUpload.Busy did the trick. See, e.g., this question, which checks Busy in a DoEvents loop.

Original answer

First of all:

  • make sure you have Option Explicit at the top of your source file.
  • make sure you have added the object reference to the HTML library you are using. Don't use CreateObject unless you have no other option!
  • make sure you have used Dim to give a specific type to all your variables — not Variant or Object.

Now, assuming you are using MSHTML, there is no function document.getElementsById. What you want is getElementById, without the "s" on "Elements." Single-step through the code — I suspect uploadForm is Nothing when you hit the For loop, so uploadForm.getElementsByTagName is raising the error.

Edit So why did I mention adding the reference above? Because if you had the reference added, and you had said Dim uploadForm as MSHTML.IHTMLElement2, the VBA editor would have changed the case to uploadForm.getElementsByTagName automatically. Since it didn't, I presume you don't have the Dim in place, or it's not a specific Dim.

(Unless, of course, you had created a variable called getelementsbytagname, which you shouldn't do :) )

Here's an MSHTML example, linked from this answer.

Community
  • 1
  • 1
cxw
  • 16,685
  • 2
  • 45
  • 81
  • Nice catches thank you, I need to brush up on the essentials. I still get the same error. It's as though there are no input tags at all in the uploadForm. I am not understanding why it will not cooperate :( – Seraphim Apr 18 '17 at 18:47
  • 1
    @Seraphim so when you single-step in the debugger, what value do you get for `uploadForm`? Also, you can add `Debug.Print` statements or use the Watch window to see the value of variables. Try [this](http://www.cpearson.com/excel/DebuggingVBA.aspx) or [this](http://www.excel-easy.com/vba/examples/debugging.html) for some debugging tutorials. – cxw Apr 18 '17 at 19:15
  • for some reason I get uploadForm = nothing. Why would it say that when there is an id "uploadForm" in the html? – Seraphim Apr 18 '17 at 19:21