Save HTML as DOCX

the other day we had a need to save an HTML file as DOCX. We are creating the HTML file using ConvertT0-HTML. The file contains data that needs to be saved in SharePoint and needs to be editable by others. We decided to save as a DOCX because those in management all have WORD installed but don't have a  Dedicated HTML editor. So here is the Code Enjoy.

!!! YOU MUST HAVE WORD 2007 or 2010 INSTALLED !!!!!

function ConvertTo-DOCX{
param($In,$Out)

#int the the enum returns for DOCX format
$SaveAs = 16

#Create WORD object and perform conversion
$Word = New-Object -ComObject Word.Application
$OpenDoc = $Word.Documents.Open($In)
$OpenDoc.SaveAs($Out,$SaveAs)
$OpenDoc.Close()

#stop all WORD instances
Get-Process | Where-Object { $_.Name -eq "WINWORD" } | Stop-Process -Force
}
comments powered by Disqus