Rory:
Background:
While writing C# based Add-in components for Office 2003 I noticed that the SaveCopyAs function that works so well in Excel, PowerPoint, Outlook, etc was absent from the Word interop assembly. After digging around for hours I found the following solution.
Solution:
public void SaveCopyAs(Word.Document wordDoc)
{
string fileName = TempFolderPath + @"\" + wordDoc.Name;
object saveFormat = Word.WdSaveFormat.wdFormatDocument;
if (Path.GetExtension(fileName).ToLower() != ".doc")
{
fileName += ".doc";
}
// There is no SaveCopyAs function in the ActiveDocument API
// Here is the workaround for that problem
object index = 1;
wordDoc.HTMLProject.HTMLProjectItems.Item(ref index).SaveCopyAs(fileName);
}
wordDoc.HTMLProject.HTMLProjectItems.Item(ref index).SaveCopyAs("c:\\1.doc");
1 comments:
Hi,
Thanks a lot.
I myself was struggling to get this api working for MS word. Your post helped a lot.
Thanks,
Siddharth Jindal
Post a Comment