Skip to content

Instantly share code, notes, and snippets.

@tiagoduarte
Created December 18, 2019 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tiagoduarte/5fde125e6b1194ddc8d005d16f258436 to your computer and use it in GitHub Desktop.
Save tiagoduarte/5fde125e6b1194ddc8d005d16f258436 to your computer and use it in GitHub Desktop.
//dlls in C:\Program Files (x86)\Microsoft Visual Studio 12.0\Visual Studio Tools for Office\PIA\Office15
using Microsoft.Office.Interop.Word;
using Microsoft.Office.Core;
Application wordApp = null;
try
{
//open a new word process
wordApp = new Application();
wordApp.Visible = false;
Document doc = wordApp.Documents.Open(filePath,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing,
Type.Missing);
if(doc.RemovePersonalInformation)
{
//update document, save and close
doc.RemovePersonalInformation = false;
doc.Close(WdSaveOptions.wdSaveChanges, Type.Missing, Type.Missing);
}
else
doc.Close(WdSaveOptions.wdDoNotSaveChanges, Type.Missing, Type.Missing);
}
catch(Exception ex)
{
}
finally
{
//close the word process
wordApp.Quit(WdSaveOptions.wdDoNotSaveChanges, Type.Missing, Type.Missing);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment