在VBA中检查URL的值

在VBA中检查URL的值,vba,excel,Vba,Excel,我正在编写一个程序,其中有一个if条件测试包含特定文本的URL,但我得到一个错误 Sub test() Dim eRow As Long Dim ele As Object Dim srlnum As String Dim wb As WebBrowser Set sht = Sheets("sheet1") RowCount = 1 sht.Range("A" & RowCount) = "Serial No" sht.Range("B" & RowCount) = "Ex

我正在编写一个程序,其中有一个if条件测试包含特定文本的URL,但我得到一个错误

Sub test()

Dim eRow As Long
Dim ele As Object
Dim srlnum As String
Dim wb As WebBrowser

Set sht = Sheets("sheet1")
RowCount = 1
sht.Range("A" & RowCount) = "Serial No"
sht.Range("B" & RowCount) = "Expiry Date"


Dim objIE As New InternetExplorer

Dim counter As Integer
counter = 1
Do While counter >= 1

    RowCount = RowCount + 1


    'srlnum = InputBox("Enter Serial Number")
    srlnum = ThisWorkbook.Sheets("sheet2").Range("A" & RowCount).Value

    With objIE
    .Visible = True

search:

   .navigate "http://tallysolutions.com/tallyweb/modules/crm/accounts/intranet/CLicenseFilterCtlr.php?strInvoker=wcc&strSearchClick=yes&strCalledFromLoginMenu=1"

    Do While .Busy Or .readyState <> 4
    DoEvents
    Loop

    Set serialnum = .document.getElementById("strInputProdSerial")
    serialnum.Value = srlnum
    .document.getElementById("btnShow").Click

    Do While .Busy Or .readyState <> 4
    DoEvents
    Loop

    On Error GoTo search

    If objIE.Url.toString.contains("http://tallysolutions.com/tallyweb/modules/crm/accounts/intranet/CSiteAdvanceSearchListCtlr.php") Then
    Stop
    End If

    For Each ele In .document.all
         Select Case ele.ID
                Case "trLicenseInfoContainer"

                      sht.Range("A" & RowCount) = srlnum
                      sht.Range("B" & RowCount) = ele.innerText

        End Select
    Next ele


     End With
     wb.Quit
     Set wb = Nothing

  counter = counter + 1

Loop

End Sub

返回一个错误,指出对象不支持此属性或方法,但我不知道此错误的含义。

您需要使用LocationURL,而不是Url

LocationURL获取当前显示的资源的URL

资料来源:

嘿,谢谢,但它给出了一个错误,因为无效限定符Stack Overflow不是一个“博客”,它是一个问答网站,因此,需要特定的细化问题,您能否进一步说明:“有没有其他方法来编写此代码”?原始帖子邀请StackOverflow社区错误地重写提供的代码,这让一些人感到困惑。这个问题实际上有一个非常简单的答案,根本不需要重写,所以人们没有理由抱怨。
If objIE.Url.toString.contains("http://tallysolutions.com/tallyweb/modules/crm/accounts/intranet/CSiteAdvanceSearchListCtlr.php") Then