У меня возникла проблема со следующим кодом PowerSehll, чтобы запустить макрос Excel и параметры передачи.Запустите макрос Excel с параметром из PowerShell
# start Excel
$excel = New-Object -comobject Excel.Application
#open file
$FilePath = 'C:\Users\{user}\Desktop\test\Macro.xlsm'
$workbook = $excel.Workbooks.Open($FilePath)
$excel.Visible = $true
#access the Application object and run a macro
$app = $excel.Application
$sourcepath = 'C:\Users\{user}\Desktop\test\FileIn.csv'
$destinationpath = 'C:\Users\{user}\Desktop\test\FileOut.xls'
$app.Run('FormatUmsatzliste',$sourcepath,$destinationpath)
$app.Quit()
Код работает нормально, и макрос выполняется, а также то, что он должен. Однако в конце появляется следующее сообщение об ошибке, и я не знаю почему.
Как я понимаю, PowerShell не нравится параметр. Надеюсь, вы можете мне помочь.
PS L:\> C:\Data\Untitled1.ps1
Exception calling "Run" with "3" argument(s): "Exception from HRESULT: 0x800A9C68"
At C:\Data\Untitled1.ps1:17 char:1
+ $app.Run('FormatUmsatzliste',$sourcepath,$destinationpath)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : COMException
OverloadDefinitions
System.Object Run(System.Object Macro, System.Object Arg1, System.Object Arg2, System.Object Arg3, System.Object Arg4, System.Object Arg5, System.Object Arg6, System.Object Arg7, System.Object Arg8, System.Object Arg9, System.Object Arg10, System.Object Arg11, System.Object Arg12, System.Object Arg13, System.Object Arg14, System.Object Arg15, System.Object Arg16, System.Object Arg17, System.Object Arg18, System.Object Arg19, System.Object Arg20, System.Object Arg21, System.Object Arg22, System.Object Arg23, System.Object Arg24, System.Object Arg25, System.Object Arg26, System.Object Arg27, System.Object Arg28, System.Object Arg29, System.Object Arg30)
System.Object _Application.Run(System.Object Macro, System.Object Arg1, System.Object Arg2, System.Object Arg3, System.Object Arg4, System.Object Arg5, System.Object Arg6, System.Object Arg7, System.Object Arg8, System.Object Arg9, System.Object Arg10, System.Object Arg11, System.Object Arg12, System.Object Arg13, System.Object Arg14, System.Object Arg15, System.Object Arg16, System.Object Arg17, System.Object Arg18, System.Object Arg19, System.Object Arg20, System.Object Arg21, System.Object Arg22, System.Object Arg23, System.Object Arg24, System.Object Arg25, System.Object Arg26, System.Object Arg27, System.Object Arg28, System.Object Arg29, System.Object Arg30)
С наилучшими пожеланиями.
Проверьте, применимо ли это: [Drop Workbook.Close из вашего макроса] (https://social.msdn.microsoft.com/Forums/office/en-US/910ada61-2c0c-4178-9ea2-2c7d0e8d6a5c/exception- from-hresult-0x800a9c68-processing-will-continue-to-be-done-on-the-file? forum = exceldev) – Vesper
Привет, Vesper, большое спасибо, это изменение решило проблему. – psychicebola
Я опубликовал это как ответ, чтобы вопрос, казалось, не был оставлен без ответа. – Vesper