Consulting

Results 1 to 3 of 3

Thread: Controlling IE sub documents from Excel VBA

  1. #1
    VBAX Regular
    Joined
    May 2010
    Posts
    6
    Location

    Controlling IE sub documents from Excel VBA

    My code:
    [vba]Sub test()
    Set IeApp = New InternetExplorer

    'Make it visible - some things don’t work
    'unless it’s visible
    IeApp.Visible = True

    'Open the page
    IeApp.Navigate "http://nepts.web.att.com/pts/main/pts.apsx#"


    'Pause the macro using a loop until the
    'page is fully loaded
    Do While IeApp.Busy
    Loop
    Do While IeApp.ReadyState <> 4
    Loop
    IeApp.Document.all.Item("3.0").Click
    IeApp.Document.getElementById("ddlPrimaryType").Value = "T"
    IeApp.Document.getElementById("ddlLocation").Value = "IL"
    IeApp.Document.getElementById("txtDescription").Value = "OPTEMAN"
    IeApp.Document.getElementById("Save").Click
    End Sub[/vba]


    I am trying to control a webpage that has sub documents or pages on it and can't seem to figure it out. When you look at the source code for the web pages there are two different source codes. There is a menu on the left side that has source code and then the page area in the middle has different source code. Whenever you select a link on the left side it goes to the correct page but always comes back with the
    "http://nepts.web.att.com/pts/main/pts/apsx#" URL. For instance, when I go to IeApp.Document.all.Item("3.0").Click from the main page it takes me to a menu on the left and then the sub document. The menu on the left has the sub document URL in it (<Item id="3.0" divider="NormalDividerMiddle" title="New Uber" on="0" url="../Uber/PTSNewUber.aspx" special="0" ischild="0" visible="1"></Item>)

    but I get an error on the statement:[vba]IeApp.Document.getElementById("ddlPrimaryType").Value = "T"[/vba]

    If I check the source of the sub document it has the info I want:
    (TD style="HEIGHT: 18px" noWrap align="right">Primary Type:</TD>
    <TD style="HEIGHT: 18px">
    <select name="ddlPrimaryType" id="ddlPrimaryType" class="plaintext" style="width:176px;">
    <option value="[Select a Primary Type]">[Select a Primary Type]</option>
    <option value="M">M - Miscellaneous</option>
    <option value="O">O - Outside Plant</option>
    <option value="P">P - Power</option>
    <option value="S">S - Switch</option>
    <option value="T">T - Transport</option>
    </select></TD>)

    I can use sendkeys to access all the information on the website but it is very unreliable. Any help would be appreciated!!!!

  2. #2
    I din't get anywhere with the URL you show in the code. It came up with an error in my browser. So without a way in to the specific page, I'll just be guessing.

    First idea, based on your comments, is that after the line:

     IeApp.Document.all.Item("3.0").Click
    you may have to wait for the page to reload. You refer to a SubDocument. Maybe this isn't quite loaded when your next line of code tries to reference it. Try inserting another wait loop before proceeding to the line that is failing.

    Given your comments about two different sections of Source code, you might want to verify the existence of Frames. Pause the code once the first page is up and in the immeadiate window do:

    ?ieapp.document.frames.length
    If this is greater than 0, you may be able to more accurately refer to the elements you need to interact with by including the correct Frame reference.

    If you can provide a URL that will get me to where you are going, I'd be glad to look further.

  3. #3
    VBAX Regular
    Joined
    May 2010
    Posts
    6
    Location
    The website site in internal to my company. As far as waiting for the code to load, I can step through to code and wait for minutes and it never loads. I think the .aspx# which has to do with ASP.Net programming. Maybe there is something I have to activate before I can access the sub document. I will try the frame thing and see if that works. Thanks!!!

Posting Permissions

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