+ Reply to Thread
Results 1 to 7 of 7

IE Automation

  1. #1
    Registered User
    Join Date
    02-14-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    55

    IE Automation

    Hi There,

    I am trying to have VBA navigate through a website but running into a proble when it comes to clicking on a link embedded on the webpage.

    IE.Document.getElementbyid("txtUsername").Value = uName

    IE.Document.getElementbyid("txtPassword").Value = pWord

    delay 1

    IE.Document.getElementbyid("btnLogin").Click

    delay 2

    This is where it fails -
    IE.Document.getElementbyid("Dynamic Doc Search").Click

    The HTML is here. for the link im trying to click.

    <a id="_ctl0_ContentPlaceHolder_aDocSearchDynamic" href="doc_search_dynamic.aspx" target="content">

    any ideas?

    I'vre tried everything and it looks like I'm not understanding how anchor tags work.

  2. #2
    Forum Contributor
    Join Date
    03-12-2013
    Location
    Chicago, USA
    MS-Off Ver
    Excel 2007
    Posts
    230

    Re: IE Automation

    I'm not completely sure, but when your code clicks the button, is the element ID name correct? From my experiences, there cannot be spaces in the name ("Dynamic Doc Search" vs "Dynamic_Doc_Search"). Not sure if its correct, but thought I'd make a suggestion.

  3. #3
    Registered User
    Join Date
    02-14-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: IE Automation

    I think what I was trying to do with the above code was to click on a button. I believe what I want to do is submit a form on that webpage. Any thoughts on that? I am coming up empty on the ol Google Search.

    Thanks!
    Last edited by alansidman; 04-25-2014 at 01:17 PM.

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    If you want to submit a form, use the form's submit method.

    For example.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  5. #5
    Registered User
    Join Date
    02-14-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: IE Automation

    Thanks Norie,

    I receive a runtime 91 error. using that code. Object variable or with block not set. any ideas what's going on there?

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Can you post the URL of the site and the rest of the code?

  7. #7
    Registered User
    Join Date
    02-14-2013
    Location
    Wisconsin, USA
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: IE Automation

    Hi Norie, the url is a company site, you will not be able to access it. Here is the VBA I'm using.

    Option Explicit
    Global oValue As Variant
    Global oType As String

    Sub ODM()

    Dim IE As Object
    Dim uName As Variant
    Dim pWord As Variant
    Dim odmSearch As Variant
    Dim frm As Object

    'On Error GoTo GetOut

    Application.ScreenUpdating = False

    UserForm1.Show

    Select Case oType
    Case Is = "HICN"
    odmSearch = "TEXTBOXzzz4___hicn"
    Case Is = "Job Document ID"
    odmSearch = "TEXTBOXzzz2___job_doc_id"
    Case Is = "DCN"
    odmSearch = "TEXTBOXzzzDCN___DCN"
    Case Is = "Member ID"
    odmSearch = "TEXTBOXzzz3___member_id"
    End Select

    uName = InputBox("Please enter User Name....")
    pWord = InputBox("Please enter Password....")

    'If pWord Or uName = "" Then
    ' Exit Sub
    ' End If


    Set IE = CreateObject("InternetExplorer.Application")
    IE.Visible = True

    IE.Navigate "https://ovationsodm.acsgs.com/login.aspx?ReturnUrl=%2findex.aspx"

    Application.StatusBar = "Submitting"
    While IE.Busy
    DoEvents
    Wend

    delay 3

    IE.document.getElementbyid("txtUsername").Value = uName
    IE.document.getElementbyid("txtPassword").Value = pWord

    delay 1

    IE.document.getElementbyid("btnLogin").Click

    delay 3

    This is where I am having problems.
    'IE.document.forms(1).submit

    'For Each link In IE.document.Links
    'If link.innerText = "_ctl0_ContentPlaceHolder_aDocSearchDynamic" Then link.Click
    'Next link


    'Set AllHyperLinks = IE.document.getElementsByTagName("A")
    ' For Each hyper_link In AllHyperLinks
    ' If hyper_link.innerText = "Dynamic Doc Search" Then
    ' hyper_link.Click
    ' Exit For
    'End If
    ' Next

    ' delay 3

    IE.document.getElementbyid(odmSearch).Value = oValue

    delay 2

    IE.document.getElementbyid("_ctl0__ctl0__ctl0_ContentPlaceHolder_ContentPlaceHolder_btnSearch").Click

    delay 2


    Application.StatusBar = "Submitted"
    'IE.Quit
    Set IE = Nothing

    delay 2

    Application.StatusBar = ""

    Application.ScreenUpdating = True

    'GetOut:
    End Sub

    This is the html I am trying to click.
    <A id=_ctl0_ContentPlaceHolder_aDocSearchDynamic href="doc_search_dynamic.aspx" target=content>Dynamic Doc Search</A>
    Last edited by specialk9203; 04-29-2014 at 10:09 AM.

+ 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. IE automation with VBA
    By kiran527 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-03-2013, 07:48 AM
  2. Excel 2007 : Automation
    By dguilloryjr in forum Excel General
    Replies: 1
    Last Post: 03-30-2009, 10:39 AM
  3. Web Automation
    By aaaaaaa in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2007, 08:12 AM
  4. Automation.
    By kymbo46 in forum Excel General
    Replies: 3
    Last Post: 04-16-2007, 08:32 AM
  5. Automation??
    By Help in automation in forum Excel General
    Replies: 1
    Last Post: 04-12-2006, 09:15 AM

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