1

I have this script which creates an outlook signature and looks over to Active Directory for date (DisplayName, Telephone, and Title).

I have this line of code to copy a .docx file to appdata and save it in html, rtf, and 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()

It works fine for Outlook 2013. But when I ran it for Outlook 2016, I get the following error

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

Is there a different formating for Outlook 2016. Thoughts?

Thanks!

Rob
  • 11
  • 3

1 Answers1

0

Try to run the script in 32-bit PowerShell f you have 32-bit Office installed.

I made a .bat file executing the below + the script

%SystemRoot%\syswow64\WindowsPowerShell\v1.0\powershell.exe c:\myscript.ps1
Richard Erickson
  • 2,568
  • 8
  • 26
  • 39
Anton
  • 1