How do I placed inside borders

SonicBoomAu

Well-known member
Joined
Oct 30, 2003
Messages
179
Location
Australia
Hi All,

I am able to place a border around a selected area within Excel but I can not figure out how to place borders inside a selection.

I.E.
Code:
 Border around Selection
objSheet.Range("B6:E55").BorderAround()

 Border Inside Selected
objSheet.Range("B6:E55").BorderInside()  ????


Any ideas welcome.
 
Hey Sonic,

Sorry I missed this one... what do you mean "boaders inside". Borders are really sort of "Interior" already, altohugh, they do show up graphically as "around". That is, Cell A1s right border looks exactly the same as Cell B1s left border, but A1s really is to the left of B1s, even if they look identical.

Can you explain further what you mean/want here, or have you figured it out..?

-- Mike
 
Mike,

What I require is the inside borders. When I use the .borderaround command. It just does the outside edge, no the interior borders / lines.

I.E.
[VB]
Border around Selection
objSheet.Range("B6:E55").BorderAround()
[/VB]

Have a look at the attachment as it will give you a better idea of what I require.

A picture is worth a thousand words. :)

Sonic
 

Attachments

To get the interior lines, you can use something like the following:
Code:
Dim myRange As Excel.Range = objSheet.Range("B6:E55")

myRange.BorderAround(ColorIndex:=xlAutomatic, Weight:=xlThin)

With myRange.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With

With myRange.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
Note that myRange.Borders(xlInsideHorizontal) and myRange.Borders(xlInsideVertical) will throw an exception if the myRange is only a single cell. So I would add some error handling to this...

Good luck! :),
Mike
 
Hi Mike,

Thanks for the helping hand.

That worked well I just had to put in the full paths.
I.E.

[VB]
With myRangePage1.Borders(Excel.XlBordersIndex.xlInsideVertical)
.LineStyle = Excel.XlLineStyle.xlContinuous
.Weight = Excel.XlBorderWeight.xlThin
.ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With

With myRangePage1.Borders(Excel.XlBordersIndex.xlInsideHorizontal)
.LineStyle = Excel.XlLineStyle.xlContinuous
.Weight = Excel.XlBorderWeight.xlThin
.ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic
End With

[/VB]

Once again thanks for your Help
 
Yeah, I apologize... I was being a little lazy. I really just quickly cleaned up some Macro Recorder code (VBA) and didnt bother looking up the necessary Imports statements. Looks like 3, eh?
Code:
Imports Excel.XlLineStyle
Imports Excel.XlBorderWeight
Imports Excel.XlColorIndex
Glad you got it. :)
 
Back
Top