• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 992
  • Last Modified:

VB.NET, Word, Paragraphs, Borders

Does anyone know how I can get the following to work?

VB.NET doesn't seem to like to apply borders unless you are dealing with a table although the VB macro editor seems to suggest this is the right way to do this.

        With objWord.Selection

            .TypeText("Summary")

            With .Borders(Word.WdBorderType.wdBorderBottom)
                .LineStyle = objWord.Options.DefaultBorderLineStyle
                .LineWidth = objWord.Options.DefaultBorderLineWidth
                .Color = objWord.Options.DefaultBorderColor
            End With

        End With

VB.NET chokes on trying to pass wdBorderBottom as an index to .Borders

The following does work in Word so I don't get what the difference is when I switch to building a word file in VB.NET

Sub Macro7()
    With Selection.Borders(wdBorderBottom)
        .LineStyle = Options.DefaultBorderLineStyle
        .LineWidth = Options.DefaultBorderLineWidth
        .Color = Options.DefaultBorderColor
    End With
End Sub
0
Knomaze
Asked:
Knomaze
1 Solution
 
tgannettsCommented:
The compiler can't determine with property of the Word.Borders class is the default one.

You need toamend the following line

With .Borders(Word.WdBorderType.wdBorderBottom)

to

With .Borders.Item(Word.WdBorderType.wdBorderBottom)

This should solve your problem.

Tom
0
 
KnomazeAuthor Commented:
WOO HOO!

Do you realize how many hours I've been trying to find that - nothing seems to reference the differenc on the net anywhere.

It also solves my problem with accessing objWord.ActiveDocument.Styles("Normal").Font

Corrected Form should be:

        objWord.ActiveDocument.Styles.Item("Normal").Font

Thank-you very much :)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now