vba完全关闭IE浏览器及调用IE浏览器的简单应用
- 2021-04-25 08:00:00
- tmtony8 翻译
- 21146
在调用IE对象时,多次调用会出现错误,防止多次调用IE对象,可以把把IE浏览器对象彻底地关闭
添加一个IE_Sledgehammer函数确保IE浏览器完全关闭
Sub IE_Sledgehammer()
Dim objWMI As Object, objProcess As Object, objProcesses As Object
Set objWMI = GetObject("winmgmts://.")
Set objProcesses = objWMI.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'iexplore.exe'")
For Each objProcess In objProcesses
On Error Resume Next
Call objProcess.Terminate
Next
Set objProcesses = Nothing: Set objWMI = Nothing
End Sub
浏览器完全关闭后,调用IE浏览器
Call IE_Sledgehammer
Set ie = CreateObject("InternetExplorer.Application")
1. VBA调用 InternetExplorer IE浏览器组件
Sub IE()
' Create Internet Explorer Application, going on the internet!
Set IE = CreateObject("InternetExplorer.Application")
' Internet Explorer Visible
IE.Visible = True
' Internet Explorer Left & Top Position on the screen
IE.Left = 0
IE.Top = 0
' Internet Explorer Height & Width Settings
IE.Height = 1024
IE.Width = 1280
' Internet Explorer Navigate To office-cn
IE.Navigate "www.office-cn.net"
To stop IE I use a command button with as code under the click event :
' Stop & Close Internet Explorer
IE.Stop
IE.Quit
End Sub
'This Must go at the top of your module. It's used to set IE as the active window
Public Declare Function SetForegroundWindow Lib "user32" (ByVal HWND As Long) As Long
Sub Automate_IE_Enter_Data()
'This will load a webpage in IE
Dim i As Long
Dim URL As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
URL = "https://www.office-cn.net"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertantly skipping over the second loop)
Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
'Webpage Loaded
Application.StatusBar = URL & " Loaded"
'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.HWND
'Set IE as Active Window
SetForegroundWindow HWNDSrc
'Find & Fill Out Input Box
n = 0
For Each itm In IE.document.all
If itm = "[object HTMLInputElement]" Then
n = n + 1
If n = 3 Then
itm.Value = "orksheet"
itm.Focus 'Activates the Input box (makes the cursor appear)
Application.SendKeys "{w}", True 'Simulates a 'W' keystroke. True tells VBA to wait
'until keystroke has finished before proceeding, allowing
'javascript on page to run and filter the table
GoTo endmacro
End If
End If
Next
'Unload IE
endmacro:
Set IE = Nothing
Set objElement = Nothing
Set objCollection = Nothing
End Sub
Access数据库自身
- office课程播放地址及课程明细
- Excel Word PPT Access VBA等Office技巧学习平台
- 将( .accdb) 文件格式数据库转换为早期版本(.mdb)的文件格式
- 将早期的数据库文件格式(.mdb)转换为 (.accdb) 文件格式
- KB5002984:配置 Jet Red Database Engine 数据库引擎和访问连接引擎以阻止对远程数据库的访问(remote table)
- Access 365 /Access 2019 数据库中哪些函数功能和属性被沙箱模式阻止(如未启动宏时)
- Access Runtime(运行时)最全的下载(2007 2010 2013 2016 2019 Access 365)
Access Activex第三方控件
- Activex控件或Dll 在某些电脑无法正常注册的解决办法(regsvr32注册时卡住)
- office使用部分控件时提示“您没有使用该ActiveX控件许可的问题”的解决方法
- RTF文件(富文本格式)的一些解析
- Access树控件(treeview) 64位Office下出现横向滚动条不会自动定位的解决办法
- Access中国树控件 在win10电脑 节点行间距太小的解决办法
- EXCEL 2019 64位版(Office 2019 64位)早就支持64位Treeview 树控件 ListView列表等64位MSCOMMCTL.OCX控件下载
- VBA或VB6调用WebService(直接Post方式)并解析返回的XML
Access ADP Sql Server等
- 早期PB程序连接Sqlserver出现错误
- MMC 不能打开文件C:/Program Files/Microsoft SQL Server/80/Tools/Binn/SQL Server Enterprise Manager.MSC 可能是由于文件不存在,不是一个MMC控制台,或者用后来的MMC版
- sql server连接不了的解决办法
- localhost与127.0.0.1区别
- Roych的浅谈数据库开发系列(Sql Server)
- sqlserver 自动备份对备份目录没有存取权限的解决办法
- 安装Sql server 2005 express 和SQLServer2005 Express版企业管理器 SQLServer2005_SSMSEE
文章分类
联系我们
| 联系人: | 王先生 |
|---|---|
| Email: | 18449932@qq.com |
| QQ: | 18449932 |
| 微博: | officecn01 |
