LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
Leo Leo is offline
external usenet poster
 
Posts: 3
Default VBA Borders in Excel 2007

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2007 - cell borders not visible when cells colored JLW1 Excel Discussion (Misc queries) 3 February 28th 11 06:33 PM
Excel 2007 - Gridlines & Borders printing problem toriel_c Excel Discussion (Misc queries) 0 October 2nd 09 03:34 PM
Innsert a row in microsft excel 2007 - rows without borders PB Excel Discussion (Misc queries) 2 September 29th 09 04:01 PM
I am having trouble printing basic cell borders in Excel 2007. Michele Excel Discussion (Misc queries) 1 July 23rd 09 02:13 AM
borders in excel 2007 Laurel Excel Discussion (Misc queries) 0 March 28th 08 06:25 AM


All times are GMT +1. The time now is 06:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"