• 0

VBA Internet Explorer Automation - Setting an element contained within a frame


Question

Morning all

 

as the title suggests im having some fun learning how to control internet explorer from within excel using vba

 

I can create an internet explorer object fine, can navigate etc, the tricky part is controlling elements on the webpage

 

I've managed to set and edit text box elements on some webpages fine, but I cant seem to do the same if the text boxes are in frames, the code wont find them

 

this is the website im playing around with: http://marstonstaverns.purchase.emea1.fourth.com/

 

and here is my code so far

 

Dim objShell As Object          'shell object
Dim objShellWindows As Object   'shell windows object
Dim objIE As Object             'Internet explorer object
Dim intTemp As Variant          'Temp integer for working
Dim docIE As HTMLDocument       'Document for Internet Explorer - the page contents?
Dim elIE As IHTMLElement        'Element for Internet Explorer - the element to control


Set objShell = CreateObject("shell.application")
Set objShellWindows = objShell.Windows
Set objIE = New InternetExplorer

'Create shells and internet explorer - note i already have ie open so dont need to make this new one visible


For intTemp = 0 To objShellWindows.Count - 1

    On Error Resume Next

    If objShellWindows.Item(intTemp) = objIE Then
        If Not InStr(0, objShellWindows.Item(intTemp).LocationURL, "marstonstaverns") = 0 Then
            Set objIE = objShellWindows.Item(intTemp)
        End If
        
    End If
    
    'loop through current ie applications until find the one for the website i want to automate
        
Next


    Set docIE = objIE.Document
    'set document to current page contents
    
    Set elIE = docIE.getElementById("txtUsername")
    'this would work if the txtusername control was not in a frame
    
    Set elIE = objIE.Document.getElementsByid(0).contentDocument.getElementsByid("txtUsername")
    'this is what im struggling to get to work


    elIE.Value = "hello"
    'this is my test line

 

 

if anyone who is more experienced with vba internet explorer can help it would be much appreciated

 

 

Cheers

Phil

 

0 answers to this question

Recommended Posts

There have been no answers to this question yet

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Why was it necessary to use AI to help write this article? Can we no longer do our own research or our own writing?
    • The auto industry really needs to update it's terminology so a software update isn't called a recall.
    • Anybody that thinks flying cars were possible are idiots. Everyone would basically need a pilot licence, can you imagine how insane and dangerous that would be, people can barely handle driving on land safely right now.
    • Microsoft Edge 149.0.4022.80 by Razvan Serea Microsoft Edge is a super fast and secure web browser from Microsoft. It works on almost any device, including PCs, iPhones and Androids. It keeps you safe online, protects your privacy, and lets you browse the web quickly. You can even use it on all your devices and keep your browsing history and favorites synced up. Built on the same technology as Chrome, Microsoft Edge has additional built-in features like Startup boost and Sleeping tabs, which boost your browsing experience with world class performance and speed that are optimized to work best with Windows. Microsoft Edge security and privacy features such as Microsoft Defender SmartScreen, Password Monitor, InPrivate search, and Kids Mode help keep you and your loved ones protected and secure online. Microsoft Edge has features to keep both you and your family protected. Enable content filters and access activity reports with your Microsoft Family Safety account and experience a kid-friendly web with Kids Mode. The new Microsoft Edge is now compatible with your favorite extensions, so it’s easy to personalize your browsing experience. Microsoft Edge 149.0.4022.80 changelog: Fixes Fixed an issue that prevented QR code generation from working. Feature updates Intune MAM Protected Downloads. The protected downloads feature for Intune MAM will now save downloaded files to the Documents > Microsoft Edge > Downloads folder in OneDrive. Extensions monitoring in the Edge management service. The Microsoft Edge management service now allows admins to gain visibility into extensions installed across their managed users. From the extensions monitoring page, admins can see which extensions have been installed as well as manage user requests for blocked extensions. For more information, see Microsoft Edge Extensions Monitoring. Validate Edge builds early with enterprise preview. Enterprise preview provides a simpler way for admins to flight pre-release Edge builds to their users. To reduce friction and bolster usage, users will receive pre-release builds directly inside of their Stable Edge application. Admins can allow users to easily opt-out of the preview experience, using built-in rollback to switch between their pre-release and stable channels with ease. Microsoft 365 admin center users can configure the feature, view their flighting population, and receive personalized recommendations all in one place. For more information, see Get started with Enterprise Preview in Microsoft Edge. Download: Microsoft Edge (64-bit) | 193.0 MB (Freeware) Download: Microsoft Edge (32-bit) | 170.0 MB Download: Microsoft Edge (ARM64) | 188.0 MB View: Microsoft Edge Website | Release History Get alerted to all of our Software updates on Twitter at @NeowinSoftware
    • The machines are starting to fight back any way they can.
  • Recent Achievements

    • Week One Done
      Eurosoft10 earned a badge
      Week One Done
    • One Month Later
      Eurosoft10 earned a badge
      One Month Later
    • One Year In
      Skeet Campbell earned a badge
      One Year In
    • One Month Later
      Sharbel earned a badge
      One Month Later
    • First Post
      BizSAR earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      598
    2. 2
      +Edouard
      189
    3. 3
      PsYcHoKiLLa
      78
    4. 4
      Michael Scrip
      76
    5. 5
      Steven P.
      69
  • Tell a friend

    Love Neowin? Tell a friend!