我有这个脚本,它创建一个 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 是否有不同的格式。想法?
谢谢!