十 31 2008
vba取得当前运行网页url地址的3种方法
是用vba获得当前网页的url的用处有很多,比如验证页面是否已经被跳转等。这里介绍3种vba获取当前网页url的实例,供大家参考。
方法一:
Sub test()
AppActivate “Internet Explorer”
SendKeys “%D^C%{TAB}”
ActiveSheet.Paste
End Sub
方法二:
本范例需要引用 Microsoft Internet Controls
‘以下程式
Private Declare Function SetForegroundWindow Lib “user32″ _
(ByVal hwnd As Long) As Long
Sub IEShell()
Dim objIE As IWebBrowser2
Dim objSW As IShellWindows
Set objSW = New SHDocVw.ShellWindows
If objSW.Count = 0 Then MsgBox “未开启InternetExplorer 应用程式”: Exit Sub
For Each objIE In objSW
aaa = Dir(objIE.FullName)
MsgBox objIE.Name & “目前开启的网址:” & objIE.LocationURL
Next objIE
End Sub
方法三:
一个更简单的方法,一并发布
Sub IEShell()
Dim Obj As Object
On Error Resume Next
For Each Obj In CreateObject(“Shell.Application”).Windows
If TypeName(Obj.document) = “HTMLDocument” Then
MsgBox Obj.Name & “当前的url是:” & Obj.LocationURL
End If
Next
End Sub
Leave a Reply
You must be logged in to post a comment.
