C
CharlieB
I have been unable to figure out how to find formatting (a style) using
Microsoft.Word.Interopt
First issue was getting an instance of a style
In the following m_WordDoc is an instance of a document in m_WordApp an
instance of word
This I discovered after much trying a way to get the "Heading 2" style as
follows:
object sStyle = "Heading 2";
object Heading2obj =
((Microsoft.Office.Interop.Word.Styles)m_WordDoc.Styles).get_Item(ref sStyle);
I made a macro in Word to find "Heading 2" style and attempted to copy it.
My code then looks like
Microsoft.Office.Interop.Word.Selection Sel1 =
m_WordApp.Selection;
Sel1.Find.ClearFormatting();
Sel1.Find.set_Style(ref Heading2obj);
Sel1.Find.ParagraphFormat.Borders.Shadow = false;
object FindText = "";
object ReplaceText = "";
object Wrap =
Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
object True=true;
object False=false;
Sel1.Find.Execute(ref FindText, //
/*in*/System.Object FindText,
ref False, //
/*in*/System.Object MatchCase,
ref False, //
/*in*/System.Object MatchWholeWord,
ref False, //
/*in*/System.Object MatchWildcards,
ref False, //
/*in*/System.Object MatchSoundsLike,
ref False, //
/*in*/System.Object MatchAllWordForms,
ref True, //
/*in*/System.Object Forward,
ref Wrap, //
/*in*/System.Object Wrap,
ref True, //
/*in*/System.Object Format,
ref ReplaceText, //
/*in*/System.Object ReplaceWith,
ref False, //
/*in*/System.Object Replace,
ref False, //
/*in*/System.Object MatchKashida,
ref False, //
/*in*/System.Object MatchDiacritics,
ref False, //
/*in*/System.Object MatchAlefHamza,
ref False) //
/*in*/System.Object MatchControl
The Find.Execute always returns false. I have tried various changes of True
and False for parameters with no luck -- Yes the document contains instances
of Heading 2 style.
The macro (recorded in Word) which works looks like
// Selection.Find.ClearFormatting
// Selection.Find.Style = ActiveDocument.Styles("Heading
2")
// Selection.Find.ParagraphFormat.Borders.Shadow = False
// With Selection.Find
// .Text = ""
// .Replacement.Text = ""
// .Forward = True
// .Wrap = wdFindContinue
// .Format = True
// .MatchCase = False
// .MatchWholeWord = False
// .MatchWildcards = False
// .MatchSoundsLike = False
// .MatchAllWordForms = False
// End With
// Selection.Find.Execute
Please Help I am going crazy.
Microsoft.Word.Interopt
First issue was getting an instance of a style
In the following m_WordDoc is an instance of a document in m_WordApp an
instance of word
This I discovered after much trying a way to get the "Heading 2" style as
follows:
object sStyle = "Heading 2";
object Heading2obj =
((Microsoft.Office.Interop.Word.Styles)m_WordDoc.Styles).get_Item(ref sStyle);
I made a macro in Word to find "Heading 2" style and attempted to copy it.
My code then looks like
Microsoft.Office.Interop.Word.Selection Sel1 =
m_WordApp.Selection;
Sel1.Find.ClearFormatting();
Sel1.Find.set_Style(ref Heading2obj);
Sel1.Find.ParagraphFormat.Borders.Shadow = false;
object FindText = "";
object ReplaceText = "";
object Wrap =
Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
object True=true;
object False=false;
Sel1.Find.Execute(ref FindText, //
/*in*/System.Object FindText,
ref False, //
/*in*/System.Object MatchCase,
ref False, //
/*in*/System.Object MatchWholeWord,
ref False, //
/*in*/System.Object MatchWildcards,
ref False, //
/*in*/System.Object MatchSoundsLike,
ref False, //
/*in*/System.Object MatchAllWordForms,
ref True, //
/*in*/System.Object Forward,
ref Wrap, //
/*in*/System.Object Wrap,
ref True, //
/*in*/System.Object Format,
ref ReplaceText, //
/*in*/System.Object ReplaceWith,
ref False, //
/*in*/System.Object Replace,
ref False, //
/*in*/System.Object MatchKashida,
ref False, //
/*in*/System.Object MatchDiacritics,
ref False, //
/*in*/System.Object MatchAlefHamza,
ref False) //
/*in*/System.Object MatchControl
The Find.Execute always returns false. I have tried various changes of True
and False for parameters with no luck -- Yes the document contains instances
of Heading 2 style.
The macro (recorded in Word) which works looks like
// Selection.Find.ClearFormatting
// Selection.Find.Style = ActiveDocument.Styles("Heading
2")
// Selection.Find.ParagraphFormat.Borders.Shadow = False
// With Selection.Find
// .Text = ""
// .Replacement.Text = ""
// .Forward = True
// .Wrap = wdFindContinue
// .Format = True
// .MatchCase = False
// .MatchWholeWord = False
// .MatchWildcards = False
// .MatchSoundsLike = False
// .MatchAllWordForms = False
// End With
// Selection.Find.Execute
Please Help I am going crazy.