views:

135

answers:

1

FYI, I'm using Perl and Win32::OLE, but the error is a Word VBA one.

Using Perl's Win32::OLE module, I'm trying to create a table in Word and format certain elements of it. I created the table (15 x 3) and successfully created a range object pointing to the cells from (2, 1) to (14, 3), i.e. all cells except the top and bottom rows.

I then set the OutsideLineStyle and InsideLineStyle and enabled borders, but the resulting table does not have vertical borders inside the table. There is a border around the entire table, and borders between the rows, but none between the columns.

I tried to rectify this by setting wdBorderVertical, but I get an error of "The requested member of the collection does not exist." I'm not sure why.

Here's my code:

    $cells = $document->Range( $table->Cell(2, 1)->Range->Start, $table->Cell(14, 3)->Range->End );
    $cells->Borders->{OutsideLineStyle} = wdLineStyleSingle;
    $cells->Borders->{OutsideLineWidth} = wdLineWidth150pt;
    $cells->Borders->{InsideLineStyle} = wdLineStyleSingle;
    $cells->Borders->{InsideLineWidth} = wdLineWidth150pt;
    $cells->Borders->Item(wdBorderRight)->{LineStyle} = wdLineStyleSingle;
    $cells->Borders->Item(wdBorderRight)->{LineWidth} = wdLineWidth150pt;

# The next two lines generate the error.
    $cells->Borders->Item(wdBorderVertical)->{LineStyle} = wdLineStyleSingle;
    $cells->Borders->Item(wdBorderVertical)->{LineWidth} = wdLineWidth150pt;

    $cells->Borders->{Enable} = 1;

Does the wdBorderVertical not exist for cell ranges? I'm trying to do this without using selection or looping, since it seems (and perhaps I'm mistaken) that Ranges are specifically used so you can avoid unnecessary looping and the like, and you can use multiple Ranges versus a single selection.

+1  A: 

It may indeed be the case that wdBorderVertical doesn't exist for cell ranges. None of the search results I found for code using wdBorderVertical applied to cell ranges, usually only to cells or tables. You may have to use a loop to get this done the way you wish.

Adam Bellaire
Hmm.. would it exist if I looped through rows?
romandas
I don't know :( ... I was just trying to research an answer, and I only see it applied to `Table`s and `Item`s....
Adam Bellaire
+1 and accepted. It doesn't exist.
romandas