|
Hi Guys, is there anyway we can find/replace text in a textbox in a word document, a function that will find any text in any sub category, header, footer, textboxt, table etc? I tried the function below but i can only find the text in the main document. all text in the textbox can't be find. I know that Textbox is in shapes (or i think it is since the only place to add a textbox is in the document.shape.addtextbox()). i tried many method including looping through each shape and use my_shape.application.selection.find method but still no luck. Please help when you get a chance. any comment/suggestion/hint would be greatly appreciated. Thanks again in advance. protected void Replace_Template(string sFile_Loc, ListItem[] li_Replaces) { if (File.Exists(sFile_Loc)) { Word.Application my_Word = new Word.Application(); my_Word.Visible = false; object oAll = Word.WdReplace.wdReplaceAll; object oTrue = true; object oFalse = false; object oMissing = System.Reflection.Missing.Value; object oFile_Loc = sFile_Loc; object oFindWrap = Word.WdFindWrap.wdFindContinue; Word.Document my_Document = (Word.Document)my_Word.Documents.Open(ref oFile_Loc, ref oMissing, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrue, ref oMissing, ref oMissing, ref oMissing); foreach (ListItem li_One in li_Replaces) { if (li_One != null) { /* object oRange_Index = 0; foreach (Word.Shape My_Shape in my_Document.Shapes) { Word.ShapeRange My_Shape_Range = my_Document.Shapes.Range(ref oRange_Index); My_Shape_Range.f } */ foreach (Word.Range My_Story in my_Document.StoryRanges) { /* foreach (Word.Shape My_Shape in my_Document.Shapes) { My_Shape.Application.Selection.Find.Replacement.ClearFormatting(); My_Shape.Application.Selection.Find.ClearFormatting(); object oFindText = li_One.Value; object oReplaceText = li_One.Text; My_Shape.Application.Selection.Find.Execute(ref oFindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrue, ref oFindWrap, ref oTrue, ref oReplaceText, ref oAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing); */ My_Story.Find.Replacement.ClearFormatting(); My_Story.Find.ClearFormatting(); object oFindText = li_One.Value; object oReplaceText = li_One.Text; My_Story.Find.Execute(ref oFindText, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oTrue, ref oFindWrap, ref oTrue, ref oReplaceText, ref oAll, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //} } } } my_Document.Save(); my_Document.Close(ref oTrue, ref oMissing, ref oMissing); my_Word.Quit(ref oTrue, ref oMissing, ref oMissing); } } |