I am converting a Word VBA macro to C# as part of a plugin I am coding.
I researched the options for converting the With
/End With
VB block to C#. And I went ahead and tried to convert my VBA PageSetup
settings:
With ActiveDocument.PageSetup
.Orientation = wdOrientPortrait
.TopMargin = InchesToPoints(0.98)
.BottomMargin = InchesToPoints(0.98)
.LeftMargin = InchesToPoints(0.92)
.RightMargin = InchesToPoints(0.92)
.Gutter = InchesToPoints(0)
.HeaderDistance = InchesToPoints(0.49)
.FooterDistance = InchesToPoints(0.49)
.PageWidth = InchesToPoints(8.5)
.PageHeight = InchesToPoints(11)
.LayoutMode = wdLayoutModeDefault
End With
So using @JohnSkeet's answer to this question, I wrote my C# code:
var oPageSetup = new Word.PageSetup
{
Orientation = Word.WdOrientation.wdOrientPortrait,
TopMargin = (float)(0.98 * 72),
BottomMargin = (float)(0.98 * 72),
LeftMargin = (float)(0.92 * 72),
RightMargin = (float)(0.92 * 72),
Gutter = (float)(0),
HeaderDistance = (float)(0.49 * 72),
FooterDistance = (float)(0.49 * 72),
PageWidth = (float)(8.5 * 72),
PageHeight = (float)(11 * 72),
LayoutMode = Word.WdLayoutMode.wdLayoutModeDefault
};
However when doing so, I get the following compiler error:
Cannot create an instance of the abstract class or interface 'Microsoft.Office.Interop.Word.PageSetup'
Can somebody advice me on what do I do wrong and how to correct my code? Thanks in advance.