1

我有这个脚本,它创建一个 Outlook 签名并查看 Active Directory 的日期(显示名称、电话和标题)。

我有这行代码可以将 .docx 文件复制到 appdata 并将其保存为 html、rtf 和 txt。

#Save new message signature 
Write-Output "Saving signatures"
#Save HTML
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatHTML");
$path = $LocalSignaturePath+'\'+$SignatureName+".htm"
$MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)

#Save RTF 
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
$path = $LocalSignaturePath+'\'+$SignatureName+".rtf"
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)

#Save TXT    
$saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatText");
$path = $LocalSignaturePath+'\'+$SignatureName+".txt"
$MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)
$MSWord.ActiveDocument.Close()
$MSWord.Quit()

它适用于 Outlook 2013。但是当我为 Outlook 2016 运行它时,我收到以下错误

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat].
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:142 char:1
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

[ref] cannot be applied to a variable that does not exist.
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:144 char:1
+ $MSWord.ActiveDocument.saveas([ref]$path, [ref]$saveFormat)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (saveFormat:VariablePath) [], RuntimeException
    + FullyQualifiedErrorId : NonExistingVariableReference

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat].
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:147 char:1
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

[ref] cannot be applied to a variable that does not exist.
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:149 char:1
+ $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$saveFormat)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (saveFormat:VariablePath) [], RuntimeException
    + FullyQualifiedErrorId : NonExistingVariableReference

Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat].
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:152 char:1
+ $saveFormat = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveForm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:TypeName) [], RuntimeException
    + FullyQualifiedErrorId : TypeNotFound

[ref] cannot be applied to a variable that does not exist.
At C:\Users\rob\Downloads\set_outlook_signature\set_outlook_signature.ps1:154 char:1
+ $MSWord.ActiveDocument.SaveAs([ref] $path, [ref]$SaveFormat)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (SaveFormat:VariablePath) [], RuntimeException
    + FullyQualifiedErrorId : NonExistingVariableReference

Outlook 2016 是否有不同的格式。想法?

谢谢!

4

1 回答 1

0

PowerShell如果您安装了 32 位 Office ,请尝试在 32 位中运行脚本。

我做了一个.bat文件执行下面+脚本

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe c:\myscript.ps1
于 2016-05-04T13:59:27.950 回答