krissi18d
03-19-2013, 11:37 AM
Hello,
Trying to create a VBA in excel to link to a website. I was able to do it using the following VBA (changing all the fields in red (sample text) below. I got to the point where it entered the log in credentials in the fields, but could not get it to click the log in buttons. Not sure if different coding is needed below to get it to the point of it logging in. Also, when the website opens, it opens in a small window. Is there a way to get it to open the internet fully expanded?
Public Sub Sample ()
Const strURL_c As String = "Sample"
Const strUsr_c As String = "Sample"
Const strPwd_c As String = "Sample"
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxPwdFld As MSHTML.HTMLInputElement
Dim tbxUsrFld As MSHTML.HTMLInputElement
Dim btnSubmit As MSHTML.HTMLInputElement
On Error GoTo Err_Hnd
'Create Internet Explorer Object
Set objIE = New SHDocVw.InternetExplorer
'Navigate the URL
objIE.Navigate strURL_c
'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
'Get document object
Set ieDoc = objIE.Document
'Get username/password fields and submit button.
Set tbxPwdFld = ieDoc.all.Item("Sample")
Set tbxUsrFld = ieDoc.all.Item("Sample")
Set btnSubmit = ieDoc.all.Item("Sample")
'Fill Fields
tbxUsrFld.Value = strUsr_c
tbxPwdFld.Value = strPwd_c
'Click submit
btnSubmit.Click
'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
Err_Hnd: '(Fail gracefully)
objIE.Visible = True
End Sub
Trying to create a VBA in excel to link to a website. I was able to do it using the following VBA (changing all the fields in red (sample text) below. I got to the point where it entered the log in credentials in the fields, but could not get it to click the log in buttons. Not sure if different coding is needed below to get it to the point of it logging in. Also, when the website opens, it opens in a small window. Is there a way to get it to open the internet fully expanded?
Public Sub Sample ()
Const strURL_c As String = "Sample"
Const strUsr_c As String = "Sample"
Const strPwd_c As String = "Sample"
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxPwdFld As MSHTML.HTMLInputElement
Dim tbxUsrFld As MSHTML.HTMLInputElement
Dim btnSubmit As MSHTML.HTMLInputElement
On Error GoTo Err_Hnd
'Create Internet Explorer Object
Set objIE = New SHDocVw.InternetExplorer
'Navigate the URL
objIE.Navigate strURL_c
'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
'Get document object
Set ieDoc = objIE.Document
'Get username/password fields and submit button.
Set tbxPwdFld = ieDoc.all.Item("Sample")
Set tbxUsrFld = ieDoc.all.Item("Sample")
Set btnSubmit = ieDoc.all.Item("Sample")
'Fill Fields
tbxUsrFld.Value = strUsr_c
tbxPwdFld.Value = strPwd_c
'Click submit
btnSubmit.Click
'Wait for page to load
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
Err_Hnd: '(Fail gracefully)
objIE.Visible = True
End Sub