Excel Hints

Results 1 to 5 of 5

Thread: Enter File Path in Webform then Submit

  1. #1

    Question Enter File Path in Webform then Submit

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

  2. #2
    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:
    [vba]objIE.Navigate "javascript: __doPostBack('LinkButtonSubmit',''")
    Do Until objIE.ReadyState = READYSTATE_COMPLETE: Loop
    [/vba] I can't test it from here because of all the relative references, but I think it will work.
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    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.

  4. #4
    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?


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

  5. #5

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •