I've got a Powershell (2.0) script that uses Microsoft.Office.Interop.Word.WdSaveFormat
to recursively open a series of html files in Word, then save as Word and Text using the wdFormatDocument
and wdFormatDOSText
parameters, respectively. The script contains a separate function for each document type.
Yesterday, the requirements changed, and I now need to output an RTF document as well. I added the $saveFormatRTF
variable
$saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDocument");
$saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatDOSText");
$saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat], "wdFormatRTF");
and got the following errors.
Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:68 char:76
+ $saveFormatDoc = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDocument");
+ CategoryInfo : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:69 char:76
+ $saveFormatTxt = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatDOSText");
+ CategoryInfo : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Unable to find type [Microsoft.Office.Interop.Word.WdSaveFormat]: make sure that the assembly containing this type is l
oaded.
At C:\users\x46332\Desktop\cgc\CGC002.PS1:70 char:76
+ $saveFormatRTF = [Enum]::Parse([Microsoft.Office.Interop.Word.WdSaveFormat] <<<< , "wdFormatRTF");
+ CategoryInfo : InvalidOperation: (Microsoft.Offic...rd.WdSaveFormat:String) [], RuntimeException
+ FullyQualifiedErrorId : TypeNotFound
Running the script converting JUST to Word and Text works fine. Running the RTF by itself it just fine. However, anytime I combine RTF in a script with other output formats, ALL output formats referenced in the script come up as "not found". Does RTF need to be exported on its own? Is there a limit to how many output file types I can have in one script (they're all separate functions, though)? Is there some parameter I'm not setting?
I have verified that the member names for output are correct, and I've scanned MSDN for clues, but can't find anything that would cause this behavior, especially the unpredictable results when adding RTF to the mix. Any ideas?