如何使用Excel VBA自动化动态更改的网页url和自动填充?

如何使用Excel VBA自动化动态更改的网页url和自动填充?,excel,vba,Excel,Vba,如何使用Excel VBA自动化动态更改的网页url和自动填充?您的问题是关于详细信息的,但据我所知,您的代码正在运行,但您希望在代码完成后打开一个新选项卡 你可以用我的一个函数来做这件事,并且有规律地使用它。这将查看打开的浏览器中的url(无论浏览器是否隐藏),并允许您将对象声明设置为包含url的选项卡 警告:正如他在评论中所说,自动操纵处理金融交易的网页是不明智的。编码中的错误可能会产生意外的结果。我个人不建议金融交易自动化,也不建议您从中获得任何建议,因为这样做的风险由您自己承担 功能:

如何使用Excel VBA自动化动态更改的网页url和自动填充?

您的问题是关于详细信息的,但据我所知,您的代码正在运行,但您希望在代码完成后打开一个新选项卡

你可以用我的一个函数来做这件事,并且有规律地使用它。这将查看打开的浏览器中的url(无论浏览器是否隐藏),并允许您将对象声明设置为包含url的选项卡

警告:正如他在评论中所说,自动操纵处理金融交易的网页是不明智的。编码中的错误可能会产生意外的结果。我个人不建议金融交易自动化,也不建议您从中获得任何建议,因为这样做的风险由您自己承担

功能: 在下面的代码中,您现在将
ie2
设置为新网页,URL字符串为
“*bildesk.com/id*”
。完成此操作后,您可以像处理第一个
IE
对象一样操作
ie2

Sub SearchBot()

    'dimension (declare or set aside memory for) our variables
    Dim IE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim y As Integer 'integer variable we'll use as a counter
    Dim result As String 'string variable that will hold our result link

    'initiating a new instance of Internet Explorer and asigning it to objIE
    Set IE = New InternetExplorer

    Dim iedoc As Object

    'navigate IE to this web page (a pretty neat search engine really)
   IE.navigate "https://www.nbpdcl.co.in/(S(qq5avnlkl4xr2iqstldu0ehl))/frmQuickBillPaymentAll.aspx"

    'wait here a few seconds while the browser is busy
    Do Until IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop

    'in the search box put cell "A2" value
    IE.document.getElementById("MainContent_txtCANO").Value = _
      Sheets("Sheet1").Range("A2").Value

    'click the 'go' button
    IE.document.getElementById("MainContent_btnSubmit").Click

  'wait here a few seconds while the browser is busy
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

    'in the amount box put cell "B2" value
    IE.document.getElementById("MainContent_txtAmountPayable").Value = _
      Sheets("Sheet1").Range("B2").Value

      'in the EMAIL box put cell "C2" value
    IE.document.getElementById("txtEmailId").Value = _
      Sheets("Sheet1").Range("C2").Value

      'in the PHONE box put cell "D2" value
    IE.document.getElementById("txtMobileNo").Value = _
      Sheets("Sheet1").Range("D2").Value

       'click the 'verify' button
    IE.document.getElementById("MainContent_rbtnlstPaymode_0").Checked = True


      'click the 'verify' button
    IE.document.getElementById("MainContent_btnConfirmPay").Click

    'wait here a few seconds while the browser is busy
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

    'click the 'verify' button
    IE.document.getElementById("MainContent_btnPayNow").Click

    '<--------- Use the function here ---------->

    Dim ie2 As InternetExplorer
    Set ie2 = GetIE("*bildesk.com/id*")


End Sub
subsearchbot()
'维度(为变量声明或留出内存)
Dim IE作为InternetExplorer表示IE浏览器的特殊对象变量
Dim aEle作为(链接)元素的HTMLLinkElement特殊对象变量
Dim y As Integer'我们将用作计数器的整数变量
Dim result作为字符串的字符串变量,它将保存我们的结果链接
启动一个新的Internet Explorer实例并将其提交给objIE
Set IE=新的InternetExplorer
Dim iedoc作为对象
'导航IE到这个网页(实际上是一个相当整洁的搜索引擎)
即“导航”https://www.nbpdcl.co.in/(S(qq5avnlkl4xr2iqstldu0ehl))/frmQuickBillPaymentAll.aspx“
'浏览器正忙时,请在此处等待几秒钟
直到IE.readyState=readyState\u完成:DoEvents:Loop
'在搜索框中输入单元格“A2”值
IE.document.getElementById(“MainContent_txtCANO”)。值=_
板材(“板材1”).范围(“A2”).值
'单击“开始”按钮
IE.document.getElementById(“MainContent\u btnSubmit”)。单击
'浏览器正忙时,请在此处等待几秒钟
当IE.Busy=True或IE.readyState 4:DoEvents:Loop时执行
'在金额框中输入单元格“B2”值
IE.document.getElementById(“MainContent\u txtAmountPayment”)。值=_
板材(“板材1”).范围(“B2”).值
'在电子邮件框中输入单元格“C2”值
IE.document.getElementById(“txtEmailId”)。值=_
板材(“板材1”).范围(“C2”).值
'在电话框中输入手机“D2”值
IE.document.getElementById(“txtMobileNo”)。值=_
图纸(“图纸1”)。范围(“D2”)。值
'单击“验证”按钮
IE.document.getElementById(“MainContent\u rbtnlstPaymode\u 0”)。选中=True
'单击“验证”按钮
IE.document.getElementById(“MainContent\u btnConfirmPay”)。单击
'浏览器正忙时,请在此处等待几秒钟
当IE.Busy=True或IE.readyState 4:DoEvents:Loop时执行
'单击“验证”按钮
IE.document.getElementById(“MainContent\u btnPayNow”)。单击
'
Dim ie2作为InternetExplorer
设置ie2=GetIE(“*bildesk.com/id*”)
端接头

因此,只需包含模块提供的功能,您就应该进行设置。

您的实际问题是什么?看起来您正在使用屏幕抓取来填充HTML表单的元素来启动公用事业账单支付。除非表单是专门为此目的设计的,并且验证非常有效,否则我不会推荐它。你只需要一个不幸的小故障,你就会发现你已经把毕生积蓄都花光了。
Sub SearchBot()

    'dimension (declare or set aside memory for) our variables
    Dim IE As InternetExplorer 'special object variable representing the IE browser
    Dim aEle As HTMLLinkElement 'special object variable for an <a> (link) element
    Dim y As Integer 'integer variable we'll use as a counter
    Dim result As String 'string variable that will hold our result link

    'initiating a new instance of Internet Explorer and asigning it to objIE
    Set IE = New InternetExplorer

    Dim iedoc As Object

    'navigate IE to this web page (a pretty neat search engine really)
   IE.navigate "https://www.nbpdcl.co.in/(S(qq5avnlkl4xr2iqstldu0ehl))/frmQuickBillPaymentAll.aspx"

    'wait here a few seconds while the browser is busy
    Do Until IE.readyState = READYSTATE_COMPLETE: DoEvents: Loop

    'in the search box put cell "A2" value
    IE.document.getElementById("MainContent_txtCANO").Value = _
      Sheets("Sheet1").Range("A2").Value

    'click the 'go' button
    IE.document.getElementById("MainContent_btnSubmit").Click

  'wait here a few seconds while the browser is busy
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

    'in the amount box put cell "B2" value
    IE.document.getElementById("MainContent_txtAmountPayable").Value = _
      Sheets("Sheet1").Range("B2").Value

      'in the EMAIL box put cell "C2" value
    IE.document.getElementById("txtEmailId").Value = _
      Sheets("Sheet1").Range("C2").Value

      'in the PHONE box put cell "D2" value
    IE.document.getElementById("txtMobileNo").Value = _
      Sheets("Sheet1").Range("D2").Value

       'click the 'verify' button
    IE.document.getElementById("MainContent_rbtnlstPaymode_0").Checked = True


      'click the 'verify' button
    IE.document.getElementById("MainContent_btnConfirmPay").Click

    'wait here a few seconds while the browser is busy
    Do While IE.Busy = True Or IE.readyState <> 4: DoEvents: Loop

    'click the 'verify' button
    IE.document.getElementById("MainContent_btnPayNow").Click

    '<--------- Use the function here ---------->

    Dim ie2 As InternetExplorer
    Set ie2 = GetIE("*bildesk.com/id*")


End Sub