title: How to call JavaScript function in VBA?
body: <p>I need to by pass an IE confirm 'OK'/'Cancel' pop-up message. I have a problem running a JavaScript function in my VBA script. My JavaScript:</p>
  
  <pre><code> function ConfirmSave()
  {
  var Ok = confirm('Are you sure all Documents and Information are attached and correct before saving?');
  
  if(Ok)
  return true;
  else
  return false;
  }
  
  
  function submitbutton_click() {
      document.getElementById('FileAttachement2_hdnButtonFlag').value = "SAVE";
      var submitbutton = document.getElementById('cmdDownSave');
      var uploadobj=document.getElementById('FileAttachement2_Uploader1');
      if(!window.filesuploaded)
      {
         if (!ConfirmSave()) return false;
          if(uploadobj.getqueuecount()&gt;0)
          {
  
              uploadobj.startupload();
          }
          else
          {
              //var uploadedcount=parseInt(submitbutton.getAttribute("itemcount"))||0;
              //if(uploadedcount&gt;0)
              //{
                  return true;
              //}
              //alert("Please browse files for upload");
          }
          return false;
      }
      window.filesuploaded=false;
      return true;
  }
  </code></pre>
  
  <p>In manual process, when I click the save button, the page will pop-up a confirm message box, and my macro will stop running when the pop-up appears unless it has been clicked.</p>
  
  <p>Here is the code I have tried, to click the save button,</p>
  
  <pre><code>Set ElementNameV = HTMLDoc.getElementsByName("cmdsave")
  ElementNameV(0).click
  </code></pre>
  
  <p>I also tried using <code>removeattribute</code> and <code>setattribute</code> with which the pop-up message disappeared but it doesn't upload the file because I need to press the 'OK' in confirm message box that will appear upon clicking the save button to start the file uploading.</p>
  
  <pre><code>ElementNameV(0).removeAttribute ("onclick")
  ElementNameV(0).setAttribute "onclick", "return true"
  ElementNameV(0).click
  </code></pre>
  
  <p>I tried running the JavaScript function using below script but it also shows the confirm pop-up message box:</p>
  
  <pre><code>Call HTMLDoc.parentWindow.execScript("submitbutton_click()")
  </code></pre>