+ Reply to Thread
Results 1 to 4 of 4

Using existing open Internet Explorer to post data from excel to the website wtih VBA

  1. #1
    Registered User
    Join Date
    04-01-2014
    Location
    Rhode Island, US
    MS-Off Ver
    Excel 2007
    Posts
    2

    Smile Using existing open Internet Explorer to post data from excel to the website wtih VBA

    I have been trying to use an already existing open Internet Explorer page to fill a form. I am new to VBA, about a week or so, but i have been able do several things with it already. As i can open a new web page and post data into it. I think i read all post relating to this topic and have found several codes that i though would work but did not.
    I have several companies that require data entry, but there website is structured in a way that after login in all sub pages shows the home URL. So i can't navigate directly. The only way i have been able to get to their forms is by coding link after links to get to the designated form that i need to complete. To work around this i though I would just open and get to the web page manually to were the form is and then run the macro at that instance to transfer data from excel to the form. I have tried changing things around, but my lack of knowledge with vba i have not been able to solve this problem.


    I have tried using google search page as the test page and inserting this to see if if it post the text "test" into the search page.
    If the code provided below is not a good code to use and for an existing open Internet Explorer page. Please provide example of one that works and were to start my personal coding into.

    .Document.getElementsByID("q")(0).Value = "test"

    In all prior codes i have viewed the two codes below seems to be the simplest, but i can't get them to work
    The second one runs and test come back as if it found it when i have it open and does nothing when i have internet explorer. I have tried posting right after this test but no matter i structure my code all i get is errors. Any help is welcomed.

    -------------------First Code--------------------
    ----> If objSW.Count Then ' new<----- I get hung up and get the following error on the first code


    run time error '91':
    Object variable or with Block variable not set


    Public Sub CheckIE()
    Dim objSW As SHDocVw.ShellWindows
    Dim objIE As SHDocVw.InternetExplorer
    Dim objDoc As Object
    Dim bAppRunning As Boolean

    'Set objSW = New SHDocVw.ShellWindows
    If objSW.Count Then ' new
    For Each objDoc In objSW
    If InStr(1, objDoc.LocationName, "Google") Then
    bAppRunning = True
    objDoc.Visible = True
    Exit For
    End If
    Next objDoc
    End If
    If bAppRunning = False Then
    Set objIE = CreateObject("InternetExplorer.Application") ' new
    objIE.Visible = True
    objIE.Navigate "www.google.com"
    End If

    Set objIE = Nothing
    Set objSW = Nothing
    End Sub

    Paul D

    ----------------------Second Code------

    Set SWs = New SHDocVw.ShellWindows


    For Each vIE In SWs
    If Left(vIE.LocationURL, 4) = "http" Then 'avoid explorer windows/etc this way
    If MsgBox("IE Window found. The URL is:" & vbCrLf & vIE.LocationURL & vbCrLf & _
    vbCrLf & "Do you want to see the html?", vbYesNo) = vbYes Then
    'Show html in a msgbox
    MsgBox vIE.Document.body.innerHTML


    'Or put it to a file
    'Dim vFF As Long
    'vff=freefile
    'open "C:\thehtml.txt" for output as #vff
    'print #vff,vie.document.body.innerhtml
    'close #vff

    End If
    End If
    Next

    Set SWs = Nothing
    Set vIE = Nothing

    End Sub

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Using existing open Internet Explorer to post data from excel to the website wtih VBA

    Try something like this. Though, I cannot say if your part of the code works.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    04-01-2014
    Location
    Rhode Island, US
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Using existing open Internet Explorer to post data from excel to the website wtih VBA

    I receive an error at IE.Document.getElementsByID("q")(0).Value = "test"
    Run-time error '438':
    Object doesn't support this property or method

    All my code is a whole bunch of the same line to fill the form(radio buttons, text box, check box, etc...), but first i have to make the web page active and ready to receive these lines of code that would be attached as "IE.Document.getElementsByID("q")(0).Value = "test"'
    Reminder i don't want to create new instance of Internet Explorer, just use the one that is open. The code you provide is contrary to what i have been seeing on my google search's, Most codes were long and running loops in the code to try find the active open website while trying to make it the active one. Hope we can make yours work
    Example of list data entered
    IE.Document.getElementsByID("q")(0).Value = "test" ' tested this one on google
    IE.Document.getElementsByID("Name")(0).Value = "Charles"
    IE.Document.getElementsByID("Date")(0).Value = "4/2/14"
    IE.Document.getElementsByID("Dollar")(0).Value = "$300"

    This is what i have tried so far:


    'With www.google.com open on Internet Explorer to see if i chooses it and enters test into search box
    Sub UseActiveOpenWebsite()
    Dim IE As Object
    'Set IE = CreateObject("InternetExplorer.Application") 'I previously use this and it works, but by opening a new Web page
    Set IE = CreateObject("Shell.Application").Windows.Item(0) ' You gave me this code and I tried it and i receive Error described about
    IE.Visible = True

    Do
    DoEvents
    Loop Until IE.ReadyState = 3

    Do
    DoEvents
    Loop Until IE.ReadyState = 4

    IE.Document.getElementsByName("q")(0).Value = "123"

    End Sub

  4. #4
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Using existing open Internet Explorer to post data from excel to the website wtih VBA

    I cannot test your lines of code without being on the same web page as you manually go to with Internet Explorer.

    I understand you're new to the forum. You should know there is a forum rule where you must surround your pasted code with CODE tags.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

    I understand you want to have VBA link to an existing IE document. The length of code to make that work is not really relevant. To be honest, I don't really understand how that one line of code I provided works. I found it somewhere on the internet and had used it once with success. Try changing the .Item number. I think that's the order of web pages you visited in IE, but I'm not sure.

    As a test, this will show you the IE document's domain name.

    Please Login or Register  to view this content.
    Sorry but that's about as much help as I can offer with IE. My knowledge and experience with this topic is limited. Good luck.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 3
    Last Post: 12-07-2014, 08:33 PM
  2. VBA to open internet explorer and in a new tab
    By puuts in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-31-2014, 05:46 AM
  3. [SOLVED] Internet Explorer - Website(s) programmatic login fails
    By J450n in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-19-2012, 08:08 PM
  4. Hyperlinks in excel open picture in internet explorer
    By Excel2003 in forum Excel General
    Replies: 8
    Last Post: 09-24-2009, 04:46 PM
  5. Replies: 5
    Last Post: 06-18-2007, 04:04 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1