Esempio n. 1
0
        public static Wd.Range Find(this Wd.Range range, Wd.WdFieldType type, string value = null)
        {
            var ShowAll = range.Document.ActiveWindow.View.ShowAll;
            var ShowFieldCodes = range.Document.ActiveWindow.View.ShowFieldCodes;

            try
            {
                range.Document.ActiveWindow.View.ShowAll = true;
                range.Document.ActiveWindow.View.ShowFieldCodes = true;
                value = string.Format("^d {0}^w{1}", type.AsGoToString(), value);

                Wd.Range result = range.Duplicate;
                Wd.Find find = result.Find;
                find.ClearFormatting();
                find.Text = value;
                find.Forward = true;
                find.Wrap = Wd.WdFindWrap.wdFindStop;
                find.Forward = true;
                find.MatchCase = false;
                find.MatchWholeWord = false;
                find.MatchWildcards = false;
                find.MatchSoundsLike = false;
                find.MatchAllWordForms = false;
                find.Execute();

                return result;
            }
            finally
            {
                range.Document.ActiveWindow.View.ShowAll = ShowAll;
                range.Document.ActiveWindow.View.ShowFieldCodes = ShowFieldCodes;
            }
        }