Hallo C# Gemeinde,
ich schreibe mir gerade ein kleines Programm, welches mir sämtliche Kommentare in allen Wordfiles in einem anzugebendem Verzeichnis entfernen soll und die Datei wieder speichern soll.
Der Code sieht ungefähr so aus:
private Word._Document oDoc;
private Word._Application oWord;
private object oMissing;
private object isVisible;
private object oInput;
private object oReadOnly;
....
this.oWord = new Word.Application();
this.oReadOnly = false;
this.oMissing = System.Reflection.Missing.Value;
oWord.Visible = false;
this.oInput = "c:\\temp\\test.docx";
try {
this.oDoc = this.oWord.Documents.Open(ref this.oInput, ref this.oMissing, this.oReadOnly, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing, false, ref this.oMissing, ref this.oMissing, ref this.oMissing, ref this.oMissing);
this.oDoc.Activate();
//this.oWord.ActiveDocument.DeleteAllComments();
this.oDoc.DeleteAllComments(); <--- "Error: Befehl nicht verfügbar"
this.oDoc.Save();
...
Leider konnte mir Google etc. nicht weiterhelfen - ich hoffe, ihr habt den entscheidenden Tipp für mich.
Herzlichen Dank,
Philipp
Gibt es auch noch eine Frage dazu? 😃
Edit:
Ich würde so was grundsätzlich nicht über das installierte Word machen, sondern über das OpenXML SDK (https://msdn.microsoft.com/de-de/library/office/bb448854.aspx).
Edit:
Und mit etwas googeln wärst du sogar auf ein Code-Beispiel gekommen: https://msdn.microsoft.com/de-de/library/office/cc850844.aspx
Guter Punkt und danke für den Hinweis - hatte vor lauter Code zusammensuchen die Frage vergessen.
Die Exception lautet "Befehl nicht verfügbar".
Das Problem hat sich aber in der Zwischenzeit erledigt, das Dokument sollte nicht im Readonly Mode aufgemacht werden 😉