title: IE automation - Excel Vba can't save value when click save button
body: <p>I am trying to do IE Automation through Excel VBA code.
  I have a web page which has cells to add value. I need to change values in these cells by code vba excel
  example:
  Now cells in webpage has value : "11_now test"
  My code vba excel:</p>
  
  <pre><code>ie.Document.getelementbyid("mx7125[R:0"]").Value = "Good" ' value i want to set
  </code></pre>
  
  <p>When run vba , webpage show value at cell is "Good" but when i click save button, the value at cell is "11_now_test"
  HTML code is as below:
  <code>
       &lt;input    aria-labelledby="" id="mx7125[R:0]" class="fld text   tt"     ctype="textbox"   li="mx7126[R:0]"  db="mx5134"   maxlength="200" style=";width:300px;"  ontr='true' async='1'  ae="setvalue"    type="text" title="Remark: 11_now_test" value="11_now_test" ov="11_now_test" work="1" fldInfo='{&amp;quot;length&amp;quot;:&amp;quot;200&amp;quot;,&amp;quot;inttype&amp;quot;:&amp;quot;0&amp;quot;}'/&gt;&lt;/div&gt;&lt;div aria-live="polite" id="mx7126[R:0]_holder" class="bc"&gt;&lt;img sf="1" aria-hidden="true" active="0" ctype="image" alt=""  src="../webclient/skins/skins-20171010-1330/tivoli09/images/blank.gif" source="blank" imgtype=".gif" style="display:inline;margin:0px;" border="0"  lc="mx7125[R:0]"    align="absmiddle" width='0px' height='26px'   id="mx7126[R:0]" title=""/&gt;&lt;/div&gt;&lt;/td&gt;
  </code></p>
  
  <p><strong>* More information*</strong></p>
  
  <p>Dear bros
  when i press F12 to inspector on webpage. If click to change value on webpage, html code at this time is:</p>
  
  <p><code>&lt;input aria-labelledby="" id="mx7125[R:0]" class="fld text   tt" ctype="textbox" li="mx7126[R:0]" db="mx5134" maxlength="200" style=";width:300px;" ontr="true" async="1" ae="setvalue" type="text" title="Remark: 11 Nov test" value="11 Nov test" ov="11 Nov test" work="1" fldinfo="{&amp;quot;length&amp;quot;:&amp;quot;200&amp;quot;,&amp;quot;inttype&amp;quot;:&amp;quot;0&amp;quot;}" originalvalue="11 Nov test" prekeyvalue="good" stoptcclick="true" keydown="false" changed_by_user="true" changed="true"&gt;
  </code>
   When type value " Good" to input cell on webpage ,prekeyvalue ="Good" and keydown will turn "True" then keydown back to "false"</p>
  
  <p><strong>* Javascrip at input cell *</strong></p>
  
  <p>when click to change value at input cell i found javascrip :</p>
  
  <pre><code>function tb_(eventOrComponent)
  {
      eventOrComponent = (eventOrComponent) ? eventOrComponent : ((window.event) ? window.event : "");
      var eventType = eventOrComponent.type;
      var textbox = this;
      if(undef(eventType) || eventType=="text") {
          eventType = "init";
          textbox = eventOrComponent;
      }
      if(DESIGNMODE)
          return;
      var ro = textbox.readOnly;
      var exc=(textbox.getAttribute("exc")=="1");
      switch(eventType)
      {
  
      case "init":
          setPromptValue(textbox.id);
          break;
      case "mousedown":
          if(getFocusId()==this.id)
              this.setAttribute("stoptcclick","true");
          break;
      case "mouseup":
          if (isIE() &amp;&amp; !hasFocus(this))
          {
              this.focus();
          }
          if (isBidiEnabled)
          {
              adjustCaret(eventOrComponent, this);
          }
          break;
      case "blur":
          input_onblur(eventOrComponent,this);
          if (isBidiEnabled)
              input_bidi_onblur(eventOrComponent, this);
          break;
      case "change":
          if(!ro)
              input_changed(eventOrComponent,this);
          break;
      case "click":
          if(overError(eventOrComponent,this))
              showFieldError(eventOrComponent,this,true);
          var liclick=this.getAttribute("liclick");
          var li=this.getAttribute("li");
          if(li!="" &amp;&amp; liclick=="1")
          {
              frontEndEvent(getElement(li),'click');
          }
  
          if(this.getAttribute("stoptcclick")=="true")
          {
              eventOrComponent.cancelBubble=true;
          }
          this.setAttribute("stoptcclick","false");
          break;
      case "focus":
          input_onfocus(eventOrComponent,this);
          if (isBidiEnabled)
              input_bidi_onfocus(eventOrComponent, this);
          this.select();
          this.setAttribute("prekeyvalue",this.value);
          break;
      case "keydown":
          this.setAttribute("keydown","true");
          if(!ro)
          {
              lastKeyPress = eventOrComponent.keyCode;
              if(eventOrComponent.ctrlKey &amp;&amp; hasKeyCode(eventOrComponent,'KEYCODE_SPACEBAR')) {
                  stopBubble(eventOrComponent);
                  eventOrComponent.cancelBubble=true;
                  eventOrComponent.returnValue=false;
                  break;
              }       
              if(isBidiEnabled)
                  processBackspaceDelete(eventOrComponent,this);
              if(hasKeyCode(eventOrComponent, 'KEYCODE_DELETE') || hasKeyCode(eventOrComponent, 'KEYCODE_BACKSPACE'))
              {
                  getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;
              }
              if((hasKeyCode(eventOrComponent, 'KEYCODE_TAB') || hasKeyCode(eventOrComponent, 'KEYCODE_ESC')))
              {
                  var taMatch = dojo.attr(this, "ta_match");
                  if(taMatch) {
                      if(taMatch.toLowerCase().indexOf(this.value.toLowerCase()) == 0)
                      {
                          console.log("tamatch="+taMatch);
                          this.value = taMatch;
                          input_keydown(eventOrComponent, this);
                          dojo.attr(this, {"prekeyvalue" : ""});
                          input_forceChanged(this);
                          inputchanged = false;
                          return; // don't want to do input_keydown again so preKeyValue will work
                      }
                  }
                  if(this.getAttribute("PopupType"))
                  {
                      var popup = dijit.byId(dojohelper.getPopupId(this));
                      if (popup)
                      {
                          dojohelper.closePickerPopup(popup);
                          if(hasKeyCode(eventOrComponent, 'KEYCODE_ESC'))
                          {
                              if (eventOrComponent.preventDefault)
                              {
                                  eventOrComponent.preventDefault();
                              }
                              else
                              {
                                  eventOrComponent.returnValue  = false;
                              }
  
                              return;
                          }
                      }
                  }
              }
              input_keydown(eventOrComponent,this);
              datespin(eventOrComponent,this);
          }
          else if(hasKeyCode(eventOrComponent,'KEYCODE_ENTER') || (hasKeyCode(eventOrComponent,'KEYCODE_DOWN_ARROW') &amp;&amp; this.getAttribute("liclick")))
          {
              var lbId = this.getAttribute("li");
              frontEndEvent(getElement(lbId), 'click');
          }
          else if(hasKeyCode(eventOrComponent,KEYCODE_BACKSPACE))
          {
              eventOrComponent.cancelBubble=true;
              eventOrComponent.returnValue=false;
          }
          break;
      case "keypress":
          if(!ro)
          {
              lastKeyPress = eventOrComponent.keyCode;
              if(eventOrComponent.ctrlKey==false &amp;&amp; hasKeyCode(eventOrComponent,'KEYCODE_ENTER'))
              {
                  var db = this.getAttribute("db");
                  if(db &amp;&amp; db!="")
                  {
                      input_forceChanged(this);
                      sendClick(db);
                      // IV32363 - When default button is a new row button, then we must set focus on 
                      // the button or the value in text box will be copied to the new row 
                      if (db)
                      {
                          window.setTimeout("focusElement(document.getElementById('"+db+"'))", 10);
                      }
                  }
              }
          }
          break;
      case "keyup":
          var keyDown = this.getAttribute("keydown");
          this.setAttribute("keydown","false");
          if(eventOrComponent.ctrlKey &amp;&amp; hasKeyCode(eventOrComponent,'KEYCODE_SPACEBAR'))
          {
              if(showFieldError(eventOrComponent,this,true))
              {
                  return;
              }
              else
              {
                  menus.typeAhead(this,0);
              }
          }
          if(!ro)
          {
              if(isBidiEnabled)
                  processBidiKeys(eventOrComponent,this);
  
              numericcheck(eventOrComponent,this);
              var min = this.getAttribute("min");
              var max = this.getAttribute("max");
  
              if(min &amp;&amp; max &amp;&amp; min!="NONE" || max!="NONE")
              {
                  if(min!="NONE" &amp;&amp; parseInt(this.value)&lt;parseInt(min))
                  {
                      this.value=min;
                      getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;
                      this.select();
                      return false;
                  }
  
                  if(max!="NONE" &amp;&amp; parseInt(this.value)&gt;parseInt(max))
                  {
                      this.value=max;
                      getHiddenForm().elements.namedItem("changedcomponentvalue").value = this.value;
                      this.select();
                      return false;
                  }
              }
              var defaultButton = false;
              if(eventOrComponent.ctrlKey==false &amp;&amp; hasKeyCode(eventOrComponent,'KEYCODE_ENTER'))
              {
                  var db = this.getAttribute("db");
                  if(db &amp;&amp; db!="")
                  {
                      defaultButton=true;
                  }
              }
              input_changed(eventOrComponent,this);
          }
          else
          {
              setFocusId(eventOrComponent,this);
          }
          if(showFieldHelp(eventOrComponent, this))
          {
              return;
          }
          if(keyDown=="true" &amp;&amp; hasKeyCode(eventOrComponent, 'KEYCODE_ENTER') &amp;&amp; !eventOrComponent.ctrlKey &amp;&amp; !eventOrComponent.altKey)
          {
              menus.typeAhead(this,0);
              return;
          }
          if(!hasKeyCode(eventOrComponent, 'KEYCODE_ENTER|KEYCODE_SHIFT|KEYCODE_CTRL|KEYCODE_ESC|KEYCODE_ALT|KEYCODE_TAB|KEYCODE_END|KEYCODE_HOME|KEYCODE_RIGHT_ARROW|KEYCODE_LEFT_ARROW')
                  &amp;&amp; !eventOrComponent.ctrlKey &amp;&amp; !eventOrComponent.altKey)
          {
              menus.typeAhead(this,0);
          }
          break;
      case "mousemove":
          overError(eventOrComponent,this);
          break;
      case "drop":
          input_onfocus(eventOrComponent,this);
          if (isBidiEnabled)
          {
              input_bidi_onfocus(eventOrComponent, this);
          }
          this.select();
          if(!ro) 
          {
              this.setAttribute("prekeyvalue",this.value);
          }
      case "cut":
      case "paste":
          if(!ro)
          {
              var fldInfo = this.getAttribute("fldInfo");
              if(fldInfo)
              {
                  fldInfo = dojo.fromJson(fldInfo);
                  if(!fldInfo.query || fldInfo.query!=true)
                  {
                      setButtonEnabled(saveButton,true);
                  }
              }
              window.setTimeout("inputchanged=true;input_forceChanged(dojo.byId('"+this.id+"'));", 20);
          }
          break;
      }
  }
  </code></pre>
  
  <p><strong>* HIDDEN FORM *</strong></p>
  
  <p>Dear @Zhi Lv - MSFT !  i tried sendkeys method but not success! i found the same problem at this <a href="https://stackoverflow.com/questions/10891556/javascript-force-an-onchange-in-maximo/16693743#16693743">link</a>. Extractly that i want to change value in maximo website, has hiddenform but at that linked they use javascript, don't use IE automation vba excel.When i inspect at input cells and type <code>document.getelementbyid("hiddenform")</code> , found this hiddenform:</p>
  
  <pre><code>&lt;form aria-hidden="true" id="hiddenform" name="hiddenform" method="POST" action="http://maximo.mysite.com/maximo/ui/maximo.jsp" style="padding:3px;"&gt;
          &lt;input type="text" size="45" name="event" id="event" title="event type"&gt;&lt;br&gt;
          &lt;input type="text" size="45" name="targetid" id="targetid" title="target id"&gt;&lt;br&gt;
          &lt;input type="hidden" size="45" name="value" id="value" value=""&gt;&lt;!-- this must be type hidden to support \n in the value --&gt;
          &lt;input type="text" size="45" name="changedcomponentid" id="changedcomponentid" title="changed component id"&gt;&lt;br&gt;
          &lt;input type="text" size="45" name="vischangedcomponentvalue" id="vischangedcomponentvalue" title="changed component value"&gt;&lt;br&gt;
          &lt;input type="hidden" name="changedcomponentvalue" value=""&gt;
          &lt;input type="text" size="45" name="currentfocus" id="currentfocus" title="focus id"&gt;&lt;br&gt;
          &lt;input name="scrollleftpos" id="scrollleftpos" size="45" title="Scroll Left"&gt;&lt;br&gt;
          &lt;input name="scrolltoppos" id="scrolltoppos" size="45" title="Scroll Top"&gt;&lt;br&gt;
          &lt;input type="text" size="45" name="uisessionid" id="uisessionid" value="4770" class="fld_ro" readonly="readonly" title="ui session id"&gt;&lt;br&gt;
          &lt;input type="text" size="45" name="csrftokenholder" id="csrftokenholder" value="ocvdjoiuq2ht8detn26pkjeekg" title="CSRF Token" readonly="readonly" class="fld_ro"&gt;&lt;br&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>thanks!!!</p>