How can I pass variable parameters into a Javascript Function using Excel VBA

后端 未结 1 937
臣服心动
臣服心动 2020-12-22 02:02

I\'m not sure if I have the correct terms above, but what I\'m trying to do is call a Javascript function passing parameters into it from an Excel File, so the function will

相关标签:
1条回答
  • 2020-12-22 02:09

    Two possible issues:

    • VBA doesn't replace variable names with their values within strings

    Example:

    Dim x as String
    x = "Hello world!"
    
    Msgbox x
    // shows "Hello world!"
    
    Msgbox "x"
    // shows "x"
    
    • Call is never required (because you can just omit parentheses instead) and can cause problems

    Example:

    Call Msgbox("x")
    // is almost exactly the same as
    Msgbox "x"
    

    Just use:

    With foo
        // do stuff
        .Document.parentWindow.execScript "FillVendorNames(" & cCode & ")", "javascript"
        // do more stuff
    End With
    
    0 讨论(0)
提交回复
热议问题