vba's ie object cannot stably access multiple web pages

daizhenbin168 注册会员
2023-02-26 19:08

The recommended solution to the problem that the ie object cannot be accessed stably when called by vba is
1. Check whether the vba version matches the ie version and change the ie version.
2. After accessing multiple, say 50, web pages using ie's navigator method in the vba program, close the ie object, reopen one, and continue. Or if an error is detected, release it and create a new one. Because the use of an ie object for a long time to connect to the browser has a long time, unstable condition, this is itself existing defects. I had a similar problem when I was working on chrome, and this is how I solved it.
3. Release unnecessary ie objects and related resources in a timely manner

dying87 注册会员
2023-02-26 19:08

This answer quotes ChatGPT

This may be because the memory usage of IE objects is too high, causing errors in the automation process. It is recommended to try the following solutions:

1. After each page is loaded, run the Quit method of the IE object to close the page and release memory. For example:

Set ie = Nothing

2. To clear the IE cache every once in a while, use the following code:

Dim ShellApp As Object
Set ShellApp = CreateObject("Shell.Application")

3. Consider using different IE objects to access different web pages, rather than reusing the same object. This avoids the problem of high memory usage. For example, you can create a new IE object each time you visit a web page:

Dim ie As Object
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.navigate "http://www.example.com"
While ie.Busy Or ie.readyState <> 4
' 处理网页内容

4. Change the Sleep function in the program to the DoEvents function. This will prevent the program from consuming too much memory during the waiting period. For example:

Dim start As Date
start = Now
Do While DateDiff("s", start, Now) < 0.5

After trying the above solutions, if you still have problems, you may want to further examine the memory footprint of your IE objects and consider optimizing or modifying your code to reduce the memory footprint.

dongxiaoyi1985 注册会员
2023-02-26 19:08

Refer to GPT and own thinking, this problem may be caused by IE object when accessing multiple web pages will produce memory leakage. After each use of an IE object, be sure to clean it up and free up all associated resources. Here are some solutions that might help:

After each web page is loaded, call the Quit method of the IE object, close it and release memory, and then create a new IE object.

Try using IE's headless browsing mode, which will not display IE on the desktop, saving some memory and resources.

Try setting the option for IE to "Open link as a new TAB" so that each new link will open in a new TAB instead of a new window, possibly reducing memory consumption.

Attempts to reduce the length of the interval in order to complete the access task faster and free up memory.

After a certain number of web pages have been visited, restart your computer to free memory.

Anyway, the solution to this problem is probably to try different methods to free up memory and avoid memory leaks.

Network fault: When you access multiple web pages, Internet Explorer may encounter network delay or disconnection. As a result, Internet Explorer cannot load web pages properly. You can use the Ping command or other network tools to check whether the network is normal.

System resource problem: When you access multiple web pages, Internet Explorer may occupy a large number of system resources, causing the system to run slowly or crash. You can use tools such as task manager to check the usage of system resources, such as CPU, memory, and disks.

Security Settings Problem: The security Settings of Internet Explorer may affect web page loading and access, for example, blocking scripts and pop-up Windows. You can check Internet Explorer's security Settings to ensure that they allow you to load and access the content of the web page you want.

About the Author

Question Info

Publish Time
2023-02-26 19:08
Update Time
2023-02-26 19:08