chetan Allipur

chetan Allipur

  • NA
  • 541
  • 166.2k

How to Insert multiple cross reference in word.

Jan 10 2018 2:20 AM
How to Insert multiple cross reference in word in different place as in word.
 
If I select different place to insert cross reference in word It is not allowing because Dialog is open. How to fix this one.
 
Here is my code
 
public void CrossReferenceItem(Office.IRibbonControl control)
{
Microsoft.Office.Interop.Word.Application app = Globals.ThisAddIn.Application;
Selection wordSelection = Globals.ThisAddIn.Application.Selection;
UndoRecord recordmacro = app.UndoRecord;
try
{
recordmacro.StartCustomRecord("Cross Reference");
Range oRange;
WdColor oColor_Old;
oRange = Globals.ThisAddIn.Application.Selection.Range;
//'Save current font color
oColor_Old = oRange.Characters[1].Font.Color;
//'Diaplay cross-reference dialog box
var CRDialog = Globals.ThisAddIn.Application.Dialogs[WdWordDialog.wdDialogInsertCrossReference];
//Thread.Sleep(100);
SendKeys.Send("%{H}");
CRDialog.Show();
CRDialog.Update();
//'Include the inserted cross-reference in oRange
oRange.End = Globals.ThisAddIn.Application.Selection.End;
//oRange.Select();
if (oRange.Fields.Count > 0)
{
for (int i = 1; i <= oRange.Fields.Count; i++)
{
oRange.Fields[i].Code.Text = oRange.Fields[i].Code.Text.Replace("MERGEFORMAT", "CHARFORMAT");
oRange.Fields[i].Code.Text = oRange.Fields[i].Code.Text + "\\* CHARFORMAT ";
if (oRange.Fields[i].Code.Text.Contains("\\h"))
{
oRange.Fields[i].Code.Font.Color = WdColor.wdColorBlue;
}
oRange.Fields[i].Update();
}
}
recordmacro.EndCustomRecord();
}
catch (Exception ex) { recordmacro.EndCustomRecord(); }
}
 
Please any one help me... 

Answers (2)