Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
The code below is designed to put medium outline and thin inside borders on
each page of a mulitpage excel worksheet. It used the BeforePrint event to do this. It worked in Excel 2003 but in 2007 on a 2 page worksheet when it calls Sub MixedBorders the bottom medium border gets erased on the first page. What do I need to change? Or is this a bug in 2007? Option Explicit Private Sub Workbook_BeforePrint(Cancel As Boolean) FormatBeforePrint End Sub Public Sub FormatBeforePrint() Dim startRow As Long Dim endRow As Long Dim startColumn As Integer Dim endColumn As Integer Dim hpb As HPageBreak 'set up the starting conditions startRow = 2 startColumn = 1 endColumn = Range("A1").CurrentRegion.Columns.Count Range("A1").Select Selection.End(xlDown).Select Range("A1").Select For Each hpb In ActiveSheet.HPageBreaks If hpb.Type = xlPageBreakManual Then hpb.Delete Next hpb For Each hpb In ActiveSheet.HPageBreaks endRow = hpb.Location.Row - 1 MixedBorders Range(Cells(startRow, startColumn), Cells(endRow, endColumn)) startRow = endRow + 1 Next endRow = Range("A1").CurrentRegion.Rows.Count MixedBorders Range(Cells(startRow, startColumn), Cells(endRow, endColumn)) End Sub Public Sub MixedBorders(ByRef rng As Range) Dim edge As Integer rng.Borders(xlDiagonalDown).LineStyle = xlNone rng.Borders(xlDiagonalUp).LineStyle = xlNone 'It fails here on 2nd pass For edge = xlEdgeLeft To xlEdgeRight With rng.Borders(edge) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 0 End With Next edge If rng.Columns.Count 1 Then With rng.Borders(xlInsideVertical) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 15 End With End If If rng.Rows.Count 1 Then With rng.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = 15 End With End If End Sub |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Excel 2007 - cell borders not visible when cells colored | Excel Discussion (Misc queries) | |||
Excel 2007 - Gridlines & Borders printing problem | Excel Discussion (Misc queries) | |||
Innsert a row in microsft excel 2007 - rows without borders | Excel Discussion (Misc queries) | |||
I am having trouble printing basic cell borders in Excel 2007. | Excel Discussion (Misc queries) | |||
borders in excel 2007 | Excel Discussion (Misc queries) |