these are the lines of code I use:
#region FindRanges
/*
* Erstellt eine Liste aus Ranges wo überall das gesuchte pattern vorhanden ist.
* Der Bereich der Range ist immer von Parent bis nach dem gesuchten pattern.
*/
public virtual List<Range> FindRanges(Range searchRange, String pattern, Boolean wildcards)
{
List<Range> ranges = new List<Range>();
Word.Document document;
Range rng;
try
{
document = searchRange.Parent;
var find = searchRange.Find;
find.Text = pattern;
find.MatchWildcards = wildcards;
find.Execute();
while (find.Found)
{
rng = document.Range(searchRange.Start, searchRange.End);
ranges.Add(rng);
find.Execute();
}
}
catch (Exception e)
{
log.Error(e);
}
return ranges;
}
#endregion FindRanges
This code looks for a certain pattern of string, for example “(-~1)([0-9]@)>” or “(-~BM)([0-9]@)>” which we pass via parameter
the method is called from here:
var pattern = "(" + id + ")(_[0-9]@)>";
var ranges = FindRanges(Document.Content, pattern, true);
Recently we received this exception with the “find.Execute()” method:
System.Runtime.InteropServices.COMException (0x800A16C9): Beim Speichern der "Rückgängig"-Information ist ein Fehler aufgetreten.
bei Microsoft.Office.Interop.Word.Find.Execute(Object& FindText, Object& MatchCase, Object& MatchWholeWord, Object& MatchWildcards, Object& MatchSoundsLike, Object& MatchAllWordForms, Object& Forward, Object& Wrap, Object& Format, Object& ReplaceWith, Object& Replace, Object& MatchKashida, Object& MatchDiacritics, Object& MatchAlefHamza, Object& MatchControl)
//(Translated into English, this roughly means: An error occurred while saving the "undo" information.)
Unfortunately I haven’t found any information about this error yet…
Thanks in advance, help would be greatly appreciated!
Leon is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.