none
input text into htm page textbox using vba from excel RRS feed

  • Question



  •     Hi,

        I am having some problem putting some text from excel into a htm file textbox located on my PC. Please see my code below:

        Sub open_manureq()
        Dim IE As Object
        Dim wd As Object


        'On Error Resume Next


        Set IE = CreateObject("InternetExplorer.Application")


        IE.navigate "C:\Program Files (x86)\DDT2000\tool_manualsend.htm"


        For Each wd In CreateObject("Shell.Application").Windows
        If wd = "Windows Internet Explorer" Then
        If InStr(LCase(wd.document.Title), "manual") <> 0 Then
        Do While wd.Busy
        DoEvents
        Loop
        wd.document.all("text1").Value = Sheet1.Range("A9").Value 'ERROR
        Exit For
        End If
        End If
        Next wd


        End Sub

        I keep getting the following error message at the line with ERROR comment:
        Method 'document' of object 'IWebBrower2' failed

        I have added "Microsoft HTML Object Library" and "Microsoft Internet Controls" vba references but I'm still getting the same error message.

        Can anyone please help

        Thanks


    • Changed type s.dinah Saturday, September 19, 2015 11:33 AM
    • Edited by s.dinah Sunday, September 20, 2015 11:13 AM
    Friday, September 18, 2015 8:02 PM

All replies

  • If I wanted to insert or replace some text in a htm file I would read the .htm file a a text file until I found a comment line acting as a placeholder, then add the specific text from Excel or replace it. Much faster, easier to write and to debug and maintain.

    So what exactly are you trying to do?


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Saturday, September 19, 2015 10:09 PM
  • Hello Rob,

    Thank you for your suggestion. However what I am trying to do is to put some text into a textbox in the htm file. I am not trying to insert or replace any text. I'm sorry if my initial post was unclear.

    The issue is that the code I used to insert the text into the textbox does not appear to be working.

    Sunday, September 20, 2015 9:32 AM
  • Did a quick search, try:

    http://stackoverflow.com/questions/20782680/set-text-in-textbox-in-internet-explorer-in-vba


    Rod Gill
    Author of the one and only Project VBA Book
    www.project-systems.co.nz

    Monday, September 21, 2015 4:37 AM
  • Rob, I had already checked out the link you suggested. It still did not work. I believe that the issue that I am having is not to do with the actual code but with the method; the error I am getting is:

     - Method 'document' of object 'IWebBrower2' failed when it tries to execute "wd.document.Title" in my code

    I would like to understand why the error is happening. I could not find an answer in the documentation for this error. Could it be PC related or because the file is a 'htm' and not a 'html' extension?

    Monday, September 21, 2015 6:10 AM
  • Please see the example here.

    http://vbadud.blogspot.com/2009/08/how-to-login-to-website-using-vba.html


    Knowledge is the only thing that I can give you, and still retain, and we are both better off for it.

    Saturday, October 10, 2015 12:52 PM