Consulting

Results 1 to 9 of 9

Thread: Solved: call a javascript function

  1. #1
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location

    Solved: call a javascript function

    Hi everybody.

    I'm working with excel vba over a web page. This page has a Javascript function "ButtonMovimenti()".

    Is there a way to call that function from vba (I'm using the reference to Internet Explorer).

    Thanks in advance
    ALe
    Help indigent families: www.bancomadreteresa.org

  2. #2
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    Well I solved it in a way but I still have some problem.

    With this line the function is called:
    [VBA]Call IE.document.parentWindow.execScript("buttonMovimenti()", "JavaScript")[/VBA]

    the fact is that I get the result page without problem only if at least one item of the webpage is selected or has focus.
    If no item has focus or selected than I'm sent to an error page.

    you know why?
    ALe
    Help indigent families: www.bancomadreteresa.org

  3. #3
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    I don't know the 'why' as there is not enough information provided to even make a S.W.A.G. - but assuming the jscript function can be normally called within the DHTML, say by clicking a button or another object you can always use something like

    .Document.GetElementsByTagName("TAG").Item(n).FireEvent("click()")

    which would then run the jscript.
    .02 Stan

  4. #4
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    stanl,

    I had already tried it but it didn't work.
    ALe
    Help indigent families: www.bancomadreteresa.org

  5. #5
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Hmmm. then perhaps something like (where myElement is a named element on the HTML page

     
    
    
    Call IE.document.parentWindow.execScript("document.all.myElement.focus();buttonMovimenti();", "JavaScript")


  6. #6
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    this way it works
    [VBA]IE.document.all.Item
    Call IE.document.parentWindow.execScript("buttonMovimenti()", "JavaScript")[/VBA]
    ALe
    Help indigent families: www.bancomadreteresa.org

  7. #7
    VBAX Master stanl's Avatar
    Joined
    Jan 2005
    Posts
    1,141
    Location
    Great! I was a little confused by the need to use 'Call' and not execute the script directly. I have used execscript() sparingly for dynamic DHTML mostly because it lacks error handling.

    I am still curious as to whether the jscript code is callable from within the page?

    Stan

  8. #8
    VBAX Mentor ALe's Avatar
    Joined
    Aug 2005
    Location
    Milan
    Posts
    383
    Location
    stanl, as you'll have noticed I'm not an expert of javascript/html.

    So I see my solution works but I don't know actually what's the point.
    ALe
    Help indigent families: www.bancomadreteresa.org

  9. #9
    VBAX Newbie
    Joined
    Feb 2014
    Posts
    1
    Location
    Can javaScript create rich interactivity? Can JavaScript create a rich interactive site like animations that when rolled over play out, or an interactive object that can be drug around the screen like a type of video game of sorts? or is Javascript limited to just hover buttons and photo gallery's thing like that?

Posting Permissions

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