VBA登录到安全网站 [英] VBA Loggin into secure websites

查看:193
本文介绍了VBA登录到安全网站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了保持这一点,我已经尝试了好几天,使用了很多代码,操纵了许多字段来尝试获得VBA代码:



1从excel宏(即yahoo.com,facebook.com)打开Web浏览器

To keep this short, I have tried for days, used many codes, manipulated many fields to try to get a VBA code to:

1 Open a web browser from an excel macro (i.e. yahoo.com,facebook.com)

2输入用户名和密码字段(有些网站在不同的页面上显示它们;即用户名页面1单击提交,第2页密码点击提交)

2 Input the Username and Password fields ( Some websites have them on different pages ; i.e. username page 1 click submit, page 2 password click submit)

3让页面打开,我将关闭它。

3 leave the page open, I will close it.

根据我的理解,我查看了网页源代码,从bbt.com我得到的用户ID字段为'usernamefield',密码字段为'userpw'

From what I understand I viewed the webpage source code and from bbt.com I got the User ID field to be 'usernamefield' and the password field to be 'userpw'

我试图获得许多代码,慷慨的人上传到网上工作,但我失败了。 对于此代码,它在此行失败:

I have tried to get many codes that generous people uploaded to the web to work but I am failing miserably.  For this code it fails at this line:

((  UserIdBox.Value = cUserID ))



谢谢为您的时间。



((  UserIdBox.Value = cUserID  ))

Thank you for your time.

Option Explicit

Sub Test()
    
    Const cURL = "americanexpress.com"
    Const cUserID = "race"
    Const cPwd = "car"
    
    Dim ie As Object
    Dim doc As HTMLDocument
    Dim PageForm As HTMLFormElement
    Dim UserIdBox As HTMLInputElement
    Dim PasswordBox As HTMLInputElement
    Dim FormButton As HTMLInputButtonElement
    Dim Elem As IHTMLElement
    
    Set ie = CreateObject("InternetExplorer.Application")
    
    ie.Visible = True
    ie.navigate cURL
    
    Do While ie.Busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
           
    Set doc = ie.document
    
    Debug.Print "Login page: " & ie.LocationURL
    For Each Elem In doc.all
        
    Next
    
    Set PageForm = doc.forms(0)
          
    Set UserIdBox = PageForm.elements("usernamefield")
    
    UserIdBox.Value = cUserID
    
    Set PasswordBox = PageForm.elements("userpw")
    
    PasswordBox.Value = cPwd
    
    PageForm.submit
    
    Do While ie.Busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
    
    Set doc = ie.document
    
    Debug.Print "Terms of Use page: " & ie.LocationURL
    For Each Elem In doc.all
        
    Next
    
    Set PageForm = doc.forms(0)

    Set FormButton = PageForm.elements("selection")
    FormButton.Click
    
    Do While ie.Busy Or Not ie.readyState = IE_READYSTATE.complete: DoEvents: Loop
    
    Set doc = ie.document
    
    Debug.Print "Main Pronto page: " & ie.LocationURL
    For Each Elem In doc.all
        
    Next




推荐答案

此代码可以帮助您完成任务。 

This code may help you in your quest. 

Dim objIExplorer As InternetExplorerPublic Sub Main()    'Reference set for: 'Microsoft Internet Controls'        Set objIExplorer = CreateObject("InternetExplorer.Application")        'Disable pop-up messages    objIExplorer.Silent = True        'Arrange Internet Explorer on the screen and make visible    objIExplorer.Top = 0    objIExplorer.Left = 0    objIExplorer.Height = 1000    objIExplorer.Width = 1250    objIExplorer.Visible = True        objIExplorer.Navigate "www.google.com"    Do While objIExplorer.Busy Or Not objIExplorer.ReadyState = 4: DoEvents: Loop    objIExplorer.Document.getElementById("q").Value = "Hi"      'Set the value in the Inputbox    End Sub




祝你好运


Good Luck


这篇关于VBA登录到安全网站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆