Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8614141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:03:10+00:00 2026-06-12T05:03:10+00:00

I create a browser like so, and manually navigate to the web page I

  • 0

I create a browser like so, and manually navigate to the web page I need to be. I intend to automatically pull certain elements once I get to the page I need to be on via a seperate macro

Sub Test()


Set CAS = New SHDocVw.InternetExplorer                     ' create a browser
CAS.Visible = True ' make it visible

CAS.navigate "http://intraneturl"

Do Until CAS.readyState = 4
DoEvents
Loop

This works fine, then I do

Public Sub Gather

Set HTMLDoc2 = CAS.document.frames("top").document

Call Timer1

With HTMLDoc2
.getElementById("tab4").FirstChild.Click
End With

Call Timer2


Dim fir, las, add1, add2, cit, stat, zi As String

Dim First As Variant
Dim Last As Variant
Dim addr1 As Variant
Dim addr2 As Variant
Dim city As Variant
Dim Thisstate As Variant
Dim Zip As Variant

Call Timer2

Set HTMLDoc = CAS.document.frames("MainFrame").document

Call Timer2

With HTMLDoc

First = .getElementsByName("IndFirst")
Last = .getElementsByName("IndLast")
addr1 = .getElementsByName("txtAdd_Line1")
addr2 = .getElementsByName("txtAdd_Line2")
city = .getElementsByName("txtAdd_City")
Thisstate = .getElementsByName("cmb_Add_State")
Zip = .getElementsByName("txtAdd_Zip")

End With



fir = First.Value
las = Last.Value
add1 = addr1.Value
add2 = addr2.Value
cit = city.Value
stat = Thisstate.Value
zi = Zip.Value

'navigate back to start page

 With HTMLDoc2
.getElementById("tab3").FirstChild.Click
End With
End Sub

This works the first time, but after the first time, I get “Object variable or with block variable not set” when trying to run the gather() sub again, on a different web page that contains similar information. Any Ideas as to what im doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T05:03:12+00:00Added an answer on June 12, 2026 at 5:03 am

    “The error “object variable or with block variable not set” occurs on: Set HTMLDoc2 = CAS.document.frames(“top”).document the second time i try running Gather().”

    This is probably one of three things:

    1. CAS is no longer an object
      To check this, set a breakpoint on the line, press ctr+G in the VBA Editor and type ?CAS Is Nothing in the Immediate Window; the result should be False; if it is True CAS is no longer an object

    2. Like Daniel Dusek suggested, make sure CAS.document.frames(“top”) is an actual element on the page.
      To check this, open the webpage you are trying to script, press F12 in Internet Explorer, click on the arrow in the toolbar and click on the “top” frame element in the webpage, switch back to the Developer Tool and look at the line highlighted. Make sure the frame element is named “top”.

    3. The HTML hasn’t fully loaded when you try to reference the frame element. Set a longer delay or a loop.

    i.e. (untested):

        Do Until HtmlDoc2 Is Nothing = false
          Set HTMLDoc2 = CAS.document.frames("top").document 
        Loop
    

    Maybe the more important question is why manually navigate to another page? Can’t you automate that part of your process too?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Create event handler for OnScroll for web browser control I would like
I'd like to create a simple browser client that I'll to demo the REST
My task is to create a simple web browser in Java. So far it
I want to create a new web-browser for android, but this browser is not
Is it possible to create a simple web browser for Android by using Monodroid?
is it possible to use python to create flash like browser games? (Actually I
I want to create something like the windows file browser upper bar.. Like url
I have a org.eclipse.swt.browser.Browser instance created in a composite. I would like to know
Is it impossible to create a browser back button, using a form or link,
For my html form, it seems that I'm unable to create cross browser hover

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.