I am attempting to execute the below code, however when my code hits my function DeleteCurrentSelectionLine
nothing is deleted.
I expect my method DeleteCurrentSelectionLine() to delete the line if replaceWithText is null. And as you see, the variable is null, but the lie is not deleted.
What do I need to alter in the syntax to make sure the information is deleted?
static void Main(string[] args)
{
Object oMissing = System.Reflection.Missing.Value;
Object oFName;
Microsoft.Office.Interop.Word.Application wrdApp = new Microsoft.Office.Interop.Word.Application();
if (wrdApp == null)
return;
Microsoft.Office.Interop.Word._Document wrdDoc;
wrdApp.Visible = true;
oFName = "C:\\Example.docx";
wrdDoc = wrdApp.Documents.OpenOld(ref oFName, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);
FindReplaceInWord(wrdDoc, wrdApp);
}
private static void ReplaceText(Microsoft.Office.Interop.Word.Application doc, Microsoft.Office.Interop.Word._Document abc, object findText, object replaceWithText)
{
object matchCase = false;
object matchWholeWord = false;
object matchWildCards = false;
object matchSoundslike = false;
object matchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
Object oClassType = "Word.DOcument.8";
Object oTrue = true;
Object oFalse = false;
Object oMissing = System.Reflection.Missing.Value;
if (replaceWithText == null)
{
DeleteCurrentSelectionLine(doc);
}
else
{
//Do Plan B
}
}
private static void FindReplaceInWord(Microsoft.Office.Interop.Word._Document wrdDoc, Microsoft.Office.Interop.Word.Application wrdApp)
{
string fv4 = null;
ReplaceText(wrdApp, wrdDoc, "@@Replace4", fv4);
}
private static void DeleteCurrentSelectionLine(Microsoft.Office.Interop.Word.Application wrdApp)
{
Object oMissing = System.Reflection.Missing.Value;
object wdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;
object wdCharacter = Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
object wdExtend = Microsoft.Office.Interop.Word.WdMovementType.wdExtend;
object count = 1;
Microsoft.Office.Interop.Word.Selection selection = wrdApp.Selection;
selection.HomeKey(ref wdLine, ref oMissing);
selection.MoveDown(ref wdLine, ref count, ref wdExtend);
selection.Delete(ref wdCharacter, ref oMissing);
}