Does VBScript allow named arguments in function calls?

前端 未结 1 690
北海茫月
北海茫月 2020-11-28 14:51

I am trying to run the following code in VBScript but it is not compiling the last statement. Is it because VBScript doesn\'t allow named argument

相关标签:
1条回答
  • 2020-11-28 15:17

    VBScript doesn't support named arguments to procedures and functions. You need to change the argument list to positional:

    Workbooks.OpenText Filename_Argument, xlMSDOS, ...
    

    VBScript also doesn't recognize Excel constants (like xlMSDOS), so you need to look them up and replace them with their numeric values:

    Workbooks.OpenText Filename_Argument, 3, ...
    

    And you must use explicit object references:

    objExcel.Workbooks.OpenText Filename_Argument, 3, ...
    

    The Excel Macro Recorder puts named arguments into positional order, so you can just delete the parameter names. Optional parameters that you don't want to specify can be omitted, e.g.:

    x = Function(Var1, , Var3)
    '                 ^
    '                 `- omitted optional 2nd parameter
    
    0 讨论(0)
提交回复
热议问题