aerospatiale Posted May 27, 2011 Posted May 27, 2011 Hello, I currently have the script (reprinted at the end of this post), which works when calling a VBA macro (which accepts parameters in Excel). The problem however is when I modify the App.Run line to accept the input parameter objects that I have picked up from the command line instead of string literals (commented out in the code below). When I do this, I receive the following error.Error: 13Error (Hex): DSource: Microsoft VBScript runtime errorDescription: Type mismatchHow can I correct this (if possible)?? My script:Dim app ' Application object handleDim wb ' Workbook object handledataFilePath = WScript.Arguments.Item(0)macroName = WScript.Arguments.Item(1)inputFilePath = WScript.Arguments.Item(2)dataParam1 = WScript.Arguments.Item(3)' Assign the application object handle to an Excel instanceSet app = CreateObject("Excel.Application")' Ensure that the user isn't bothered by the temporary instance of Excelapp.Visible = Falseapp.DisplayAlerts = False' Open the workbook containing the relevant macros to be runOn Error Resume NextSet wb = app.Workbooks.Open(dataFilePath)If Err.Number <> 0 Then Call reportErrorEnd If' I would prefer to type the more dynamic: app.Run macroName, inputFilePath, dataParam1app.Run "literalMacroName", "literalInputFilePath", "literalDataParam1"If Err.Number <> 0 Then Call reportErrorEnd If
gunsmokingman Posted May 27, 2011 Posted May 27, 2011 This is not the correct way of using the Run Methodapp.Run "literalMacroName", "literalInputFilePath", "literalDataParam1"Would Be more correct.app.Run "literalMacroName"& "literalInputFilePath"&"literalDataParam1"VBS Run MethodProblem 1If you are trying to pass varibles make sure these exists in your script, the belowwould only be process as string. They would not be process as Varibles."literalMacroName", "literalInputFilePath", "literalDataParam1"Example Of Varibles With Quotes
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now