PDA

View Full Version : Enter File Path in Webform then Submit



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".

Oorang
06-02-2008, 11:40 AM
Hi Elmura,
Thanks so much for thinking to post the site source code! Most people don't think of the very helpful step. The issue you are having here is that the submit button isn't of the InputElement type. It's not really a button at all:) You can sneak around this by just calling the javascript the "button" is. If you look at where it is at you will notice if all conditions are met it is call the JavaScript sub: "__doPostBack"
You should be able call this sub using the ie.navigate method like so:
objIE.Navigate "javascript: __doPostBack('LinkButtonSubmit',''")
Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
I can't test it from here because of all the relative references, but I think it will work.

Elmura
06-02-2008, 06:13 PM
Hi Oorang, thankyou for responding.
Remmed out the btnSubmit lines & inserted your code (with a dble quote after the close bracket) but nothing happened.
Also, any idea how I can populate the form field with my file path?

I've attached a cutdown, shrunken screenshot for reference.

Elmura
06-05-2008, 08:12 PM
I ran some code for links retrieval and got this response. How can I make use of this to populate the file path box and submit the file link?

:hi:
javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("LinkButtonSubmit", "", true, "", "", false, true))

Elmura
06-12-2008, 06:14 AM
Bump! Help!