Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Range.Information not Working C#

Tags:

c#

range

vb.net

I am currently in the process of fixing errors that showed up in C# code after it has been converted from Visual Basic. In my C# code I have the following:

Pos = oWord.InchesToPoints(7);
oDoc.Bookmarks["\\endofdoc"].Range.InsertParagraphAfter();
do
{
    oRng = oDoc.Bookmarks["\\endofdoc"].Range;
    oRng.ParagraphFormat.SpaceAfter = 6;
    oRng.InsertAfter("");
    oRng.InsertParagraphAfter();
} while (Pos >= oRng.Information(WdInformation.wdVerticalPositionRelativeToPage));

The problem I am having is with this section:

oRng.Information(WdInformation.wdVerticalPositionRelativeToPage)

I have the error "Indexed property 'Microsoft.Office.Interop.Word.Range.Information' has non-optional arguments which must be provided."

The type the arguments must be is WdInformation, according to msdn. I double checked and wdVerticalPositionRelativeToPage is that type. What am I doing wrong? Any help will greatly be appreciated.

If it helps, here is the same code in VB before the conversion:

Pos = oWord.InchesToPoints(7)
oDoc.Bookmarks.Item("\endofdoc").Range.InsertParagraphAfter()
    Do
        oRng = oDoc.Bookmarks.Item("\endofdoc").Range
        oRng.ParagraphFormat.SpaceAfter = 6
        oRng.InsertAfter("")
        oRng.InsertParagraphAfter()
    Loop While Pos >= oRng.Information(Word.WdInformation.wdVerticalPositionRelativeToPage)
like image 650
Jared.Rodgers Avatar asked Apr 17 '26 08:04

Jared.Rodgers


1 Answers

The error message is clearly states that the Range.Information is indexer.

Use this syntax:

oRng.Information[WdInformation.wdVerticalPositionRelativeToPage];
like image 141
Hamlet Hakobyan Avatar answered Apr 18 '26 22:04

Hamlet Hakobyan