/// <summary> /// Call VBA script from one of Office applications. /// List of accepted apps: Excel, Word, Powerpoint, Outlook /// </summary> /// <param name="processName">Name of the process being executed</param> /// <param name="officeAppName">One of the office app names</param> /// <param name="filePath">File path with the VBA script to be executed</param> /// <param name="macroName">VBA script name with module/procedure name</param> /// <param name="macroArgs">List of object args to be used in the script</param> /// <param name="showAlerts">Boolean status to show alerts on open application</param> /// <param name="visibleApp">Boolean status to show open application</param> /// <param name="saveFile">Boolean status to save or not the file</param> /// <param name="stw">Stream writer object to output message to stream buffer</param> /// <returns>Returned string from VBA Main Function</returns> public static string RunVBAscript(string processName, string officeAppName, string filePath, string macroName, object[] macroArgs, bool showAlerts = false, bool visibleApp = false, bool saveFile = false, StreamWriter stw = null) { object[] _macroNameArray = new object[] { macroName }; object[] combinedMacroNameAndArgs = ObjectService.ConcatArrays(_macroNameArray, macroArgs); switch (officeAppName) { case ConstantsService.NAME_SW_OFFICE_EXCEL: return(_RunVBAonExcel(processName, officeAppName, filePath, combinedMacroNameAndArgs, showAlerts, visibleApp, saveFile, stw)); case ConstantsService.NAME_SW_OFFICE_WORD: return(_RunVBAonWord(processName, officeAppName, filePath, combinedMacroNameAndArgs, showAlerts, visibleApp, saveFile, stw)); case ConstantsService.NAME_SW_OFFICE_POWERPOINT: return(_RunVBAonPowerpoint(processName, officeAppName, filePath, combinedMacroNameAndArgs, showAlerts, visibleApp, saveFile, stw)); case ConstantsService.NAME_SW_OFFICE_OUTLOOK: return(_RunVBAonOutlook(processName, officeAppName, filePath, macroName, showAlerts, visibleApp, saveFile, stw)); default: return("ERROR | Office application " + officeAppName + " not specified or accepted!"); } }