Elmura
06-01-2008, 10:52 PM
Hi guys. New here & not too good at VBA.
I need to upload a file to two secure sites. I've been able upload via SendKeys for one of them but it sometimes doesn't work properly. I've adapted Oorang's web entry template below.
For some reason, the code opens the page (after I have previously logged in to it), but doesn't specify the file or click submit. I have attached the source code of the site (very little html in it). References to MS HTML object & Internet Controls have been included in VBA.
Public Sub OpenVIC()
Const strURL_c As String = "SecureSiteName"
Const strFile As String = "C:\Files\export.bet"
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxFileFld 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 file field and submit button.
Set tbxFileFld = ieDoc.all.Item("FileBatch")
Set btnSubmit = ieDoc.all.Item("LinkButtonSubmit")
'Fill Fields
tbxFileFld.Value = strFile
'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
What am I doing wrong? The fields FileBatch and LinkButtonSubmit were taken from the source code but are probably wrong - or the type is wrong. I'm at a loss. Please help...
PS: There is only one input box and three buttons. One is "Browse" to the filepath manually, 2nd is to "close" the window and the critical one is "Submit Batch File".
I need to upload a file to two secure sites. I've been able upload via SendKeys for one of them but it sometimes doesn't work properly. I've adapted Oorang's web entry template below.
For some reason, the code opens the page (after I have previously logged in to it), but doesn't specify the file or click submit. I have attached the source code of the site (very little html in it). References to MS HTML object & Internet Controls have been included in VBA.
Public Sub OpenVIC()
Const strURL_c As String = "SecureSiteName"
Const strFile As String = "C:\Files\export.bet"
Dim objIE As SHDocVw.InternetExplorer
Dim ieDoc As MSHTML.HTMLDocument
Dim tbxFileFld 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 file field and submit button.
Set tbxFileFld = ieDoc.all.Item("FileBatch")
Set btnSubmit = ieDoc.all.Item("LinkButtonSubmit")
'Fill Fields
tbxFileFld.Value = strFile
'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
What am I doing wrong? The fields FileBatch and LinkButtonSubmit were taken from the source code but are probably wrong - or the type is wrong. I'm at a loss. Please help...
PS: There is only one input box and three buttons. One is "Browse" to the filepath manually, 2nd is to "close" the window and the critical one is "Submit Batch File".