Forum Discussion
Convert compatibility legacy doc to docx
Hello M_sqd,
Script that you are referring to is using SaveAs method, but Microsoft.Office.Interop.Word also contains SaveAs2 method which has CompatibilityMode parameter.
This parameter is based on WdCompatibilityMode Enum (WdCompatibilityMode Enum (Microsoft.Office.Interop.Word) | Microsoft Learn) and has the following values:
wdCurrent | 65535 | Compatibility mode equivalent to the latest version of Word. |
wdWord2003 | 11 | Word 2010 is put into a mode that is most compatible with Word 2003. Features new to Word 2010 are disabled in this mode. |
wdWord2007 | 12 | Word 2010 is put into a mode that is most compatible with Word 2007. Features new to Word 2010 are disabled in this mode. |
wdWord2010 | 14 | All Word 2010 features are enabled. |
wdWord2013 | 15 | Default. All Word 2013 features are enabled. |
So to fit your specific use case, you need to adjust your $document.SaveAs line to something like this:
$document.SaveAs2([ref]$docx_filename, [ref]$Format, [ref][Microsoft.Office.Interop.Word.WdCompatibilityMode]::wdCurrent)
Hope that helps.
- EvanSullivan37Apr 24, 2023Copper Contributor
I am trying to use the same code the OP is using and making your changes. However I get the error. For the record line 10 is just "$document.Close()"
Parameter value was out of acceptable range
At line:10 char:5
+ $document.SaveAs2([ref]$docx_filename, [ref]$Format, [ref][Micros ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServices.COMException- AndySvintsMay 01, 2023Iron Contributor
- Paul1460Oct 11, 2024Copper Contributor
AndySvints, did you manage to get the document.SaveAs2 code working?