Excel workbooks.saveas() error in powershell

荒凉一梦 提交于 2019-12-06 23:45:27
Ansgar Wiechers

Constants passed into the SaveAs method usually represent numeric values, not strings. In your case the second parameter probably should be 51 (xlWorkbookDefault) as documented here. Same goes for the other two strings ("xlNoChange", which should be 1, and "xlLocalSessionChanges", which should be 2). You need to either use the numeric values, or define the constants yourself, e.g.:

$xlWorkbookDefault     = 51
$xlNoChange            =  1
$xlLocalSessionChanges =  2

Also, you cannot use $null for arguments that should retain default values. Use [Type]::Missing instead.

Change this:

$opendoc.saveas($basename,$saveFormat,$null,$null,$false,$false,"xlNoChange","xlLocalSessionChanges")

into this:

$opendoc.SaveAs($basename, 51, [Type]::Missing, [Type]::Missing, $false, $false, 1, 2)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!