Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

' Border around Selection
objSheet.Range("B6:E55").BorderAround()

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

 

 

Any ideas welcome.

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

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 A1's right border looks exactly the same as Cell B1's left border, but A1's really is to the left of B1's, even if they look identical.

 

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

 

-- Mike

Posting Guidelines

 

Avatar by Lebb

Posted

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.

' Border around Selection
objSheet.Range("B6:E55").BorderAround()

 

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

Border Example.zip

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted

To get the interior lines, you can use something like the following:

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

Posting Guidelines

 

Avatar by Lebb

Posted

Hi Mike,

 

Thanks for the helping hand.

 

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

I.E.

 

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

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

 

Once again thanks for your Help

Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

-- Rick Cook, The Wizardry Compiled

Posted
Yeah, I apologize... I was being a little lazy. I really just quickly cleaned up some Macro Recorder code (VBA) and didn't bother looking up the necessary Imports statements. Looks like 3, eh?
Imports Excel.XlLineStyle
Imports Excel.XlBorderWeight
Imports Excel.XlColorIndex

Glad you got it. :)

Posting Guidelines

 

Avatar by Lebb

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...