PowerShell-Script to execute Excel-Macro on a Terminal-Server

-1

I have a problem running a batchjob on a Terminalserver which invokes a PowerShell script to execute an Excel macro.

Batch -> PowerShell -> Excel

Batchcode:

C:\...\v1.0\powershell.exe -file D:\...\macroSchedule\VV_198_PFM_exec_macro.ps1

PowerShellCode:

# start Excel
$excel = New-Object -comobject Excel.Application

#open file
$macro_file = 'D:\...\macroSchedule\Makro_V2.xlsm'

#make it visible (just to check what is happening)
$excel.Visible = $true
$excel.DisplayAlerts = $false

$workbook = $excel.Workbooks.Open($macro_file)

#access the Application object and run a macro
$app = $excel.Application
$file_in = 'D:\...\LISTE_20150703_20150703213501_.csv'
$file_out = 'D:\...\LISTE_20150703_20150703213501.xls'

$app.Run('FormatListe',$file_in,$file_out)
$app.Quit()

When I execute the batch file I receive the following error messages:

Exception setting "DisplayAlerts": "Old format or invalid type library. (Exception from HRESULT: 0x80028018 (TYPE_E_INV
DATAREAD))"
At D:\...\VV_198_PFM_exec_macro.ps1:9 char:8
+ $excel. <<<< DisplayAlerts = $false
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

Exception calling "Open" with "1" argument(s): "Old format or invalid type library. (Exception from HRESULT: 0x80028018
(TYPE_E_INVDATAREAD))"
At D:\...\VV_198_PFM_exec_macro.ps1:12 char:34
+ $workbook = $excel.Workbooks.Open <<<< ($macro_file)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : ComMethodTargetInvocation

Exception calling "Run" with "31" argument(s): "Cannot run the macro 'FormatUmsatzliste'. The macro may not be availabl
e in this workbook or all macros may be disabled."
At D:\...\VV_198_PFM_exec_macro.ps1:20 char:9
+ $app.Run <<<< ('Formatliste',$file_in,$file_out)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
excel
vba
powershell
batch-file
terminal-services
asked on Stack Overflow Aug 20, 2015 by psychicebola • edited Aug 20, 2015 by Ansgar Wiechers

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0