Solved

Formatting an excel cell - Borders

Posted on 2006-07-05
8
234 Views
Last Modified: 2010-04-23
Friends,

I need to put a border around each individual cell that I am including in a spreadsheet      The Range includes A1 through O22

So, I guess what I'm asking is what would the property setting (syntax) be?

Here is my code that accompanies it:

 With oSheet.Range("A1", "O" & NumberOfCarsInRace + 3)

            .VerticalAlignment = excel.XlVAlign.xlVAlignCenter
            .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter

            '.Borders.Application.????????????????
0
Comment
Question by:indy500fan
  • 4
  • 4
8 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 17045526
With oSheet.Range("A1", "O" & NumberOfCarsInRace + 3)
         .VerticalAlignment = excel.XlVAlign.xlVAlignCenter
         .HorizontalAlignment = excel.XlHAlign.xlHAlignCenter

    With .Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With .Borders(xlEdgeRight)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
  End With
0
 

Author Comment

by:indy500fan
ID: 17045580
I'm getting errors with the xl* items.  Is there something I need to declare that I'm not?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17045621
I now see that you are in VB.net.

as I don't have VB.net handy, you will have to find the correct syntax, it will be similar to this:
xlContinuous  should be excel.XlLineStyle.xlLineStyleContinuous
etc
0
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

Author Comment

by:indy500fan
ID: 17045715
??? Actually, I need help with that.  

As you said excel.XlLineStyle.xlLineStyleContinuous works, but I can't make the

With .Borders(xlEdgeBottom) work.
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17045753
xlEdgeBottom - > excel.XlBordersIndex.xlEdgeBottom
xlThin -> excel.XlBorderWeight.xlThin
xlAutomatic ->  Excel.XlColorIndex.xlColorIndexAutomatic
0
 

Author Comment

by:indy500fan
ID: 17045799
AngelIII,

Okay, that compiled, thanks for that; however, it puts a border around the whole set rather than each cell as I requested.  Any other suggestions?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17045821
indeed, I forgot to copy 2 blocks:

    With .Borders(excel.XlBordersIndex.xlInsideVertical)
        .LineStyle = excel.XlLineStyle.xlContinuous
        .Weight = excel.XlBorderWeight.xlThin
        .ColorIndex = Excel.XlColorIndex.xlAutomatic
    End With
    With .Borders(excel.XlBordersIndex.xlInsideHorizontal)
        .LineStyle = excel.XlLineStyle.xlContinuous
        .Weight = excel.XlBorderWeight.xlThin
        .ColorIndex = Excel.XlColorIndex.xlAutomatic
    End With
0
 

Author Comment

by:indy500fan
ID: 17045907
angellIII,

Brilliant!  That works.  Thank you.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now