I have created an application that places a piece of specified text in the footer of the document when a button is pressed.
The trouble is that I would like this string to always appear on the top line of the footer, aligned to the right hand side.
Is there a way to align one piece of text in the footer so that it will always appear in the top right of the footer?
Well let me say that this will require more research how to get the correct position and probably some hardcoded adjustment. Takes this code as a starting point
There are quite a lot of problems you will have to solve, like Do you really want to use only section 1? Do you really want to use only primary footer? Is PageSetup good enough for getting the correct position?
Also the line
shp.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionBottomMarginArea;
doesn't seem to have any impact but via Word UI you can set it. This would be good to explore in more detail as it would save you a lot of calculation
using System;
using Word = Microsoft.Office.Interop.Word;
namespace WordAddIn1
{
public class Class1
{
public void InsertShape(Word.Document doc)
{
try
{
Word.Section sec = doc.Sections[1];
Word.HeaderFooter foo = sec.Footers[Word.WdHeaderFooterIndex.wdHeaderFooterPrimary];
Word.Range rng = foo.Range;
float leftPos = doc.PageSetup.PageWidth - doc.PageSetup.RightMargin;
float topPos = doc.PageSetup.PageHeight - doc.PageSetup.BottomMargin;
Word.Shape shp = doc.Shapes.AddTextbox(Microsoft.Office.Core.MsoTextOrientation.msoTextOrientationHorizontal,
leftPos, topPos, 50, 20, rng);
shp.TextFrame.TextRange.Text = "Text";
shp.RelativeVerticalPosition = Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionBottomMarginArea;
}
catch (Exception)
{
throw;
}
}
}
}