2012-03-12 73 views
0

它是在Excel 2003中VBAPowershell:如何设置excel应用程序的计算模式?

Application.Calculation = xlCalculationManual 

我想实现在PowerShell中的相同。这是我做过什么:

$excel = New-Object -com Excel.Application 
$xlCalculationManual = -4135 
$excel.Calculation = $xlCalculationManual 

值-4135从那里得到:http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.constants%28v=office.14%29.aspx

它抛出一个异常:

Exception setting "Calculation": "Unable to set the Calculation property of the Application class" 
At C:\Documents and Settings\AUser\Desktop\ppp2eikon.ps1:11 char:8 
+ $excel. <<<< Calculation = $xlCalculationManual 
    + CategoryInfo   : InvalidOperation: (:) [], RuntimeException 
    + FullyQualifiedErrorId : PropertyAssignmentException 

什么是设置此属性的正确方法?

回答

1

至少在VBA中,如果没有至少一个打开的工作簿,则无法设置计算模式。引发的错误是:1004 - 应用程序定义的或对象定义的错误

尝试首先打开工作簿。

相关问题