estoy tratando de aplicar margenes diferentes a paginas distintas segun si la pagina es par o impar
public void macro(Document doc)
{
object Miss = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Word.WdStatistic PagesCountStat = Microsoft.Office.Interop.Word.WdStatistic.wdStatisticPages;
int PagesCount = doc.ComputeStatistics(PagesCountStat, ref Miss);
MessageBox.Show("Paginas totales: " + PagesCount);
float imparIzq = 0;
float imparDer = 0;
float parIzq = 2;
float parDer = 2;
object What = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
object Which = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute;
object CurrentPageNumber;
object NextPageNumber;
var app = Globals.ThisAddIn.Application;
for (int x = 0; x <= PagesCount; x++)
{
CurrentPageNumber = (Convert.ToInt32(x.ToString()));
NextPageNumber = (Convert.ToInt32(x.ToString() + 1));
doc.Application.Selection.GoTo(ref What, ref Which, ref CurrentPageNumber, ref Miss);
Range rge = doc.Application.Selection.Range;
doc.Application.Selection.GoTo(ref What, ref Which, ref CurrentPageNumber, ref Miss);
rge.End = doc.Application.Selection.Range.End;
doc.Application.Selection.Select();
if (x % 2 == 0)//paginas pares
{
doc.Application.Selection.PageSetup.LeftMargin = parIzq;
doc.Application.Selection.PageSetup.RightMargin = parDer;
}
else //paginas impares
{
doc.Application.Selection.PageSetup.LeftMargin = imparIzq;
doc.Application.Selection.PageSetup.RightMargin = imparDer;
}
}
}
Por más que lo intente no se cambian los margenes de la pagina, no hace nada o solo se cambiar a nivel global el ultimo margen. Agradezco de antemano si alguien puede ayudarme.