none
Excel 2007 setting Border.LineStyle

    Question

  • This code works for pre-Excel 2007 and not Excel 2007:

    (1) style.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;

    if I change it to the following (casting the constant instead of using the XlBordersIndex value)it will work in 2007:

    (2) style.Borders[(Excel.XlBordersIndex)Excel.Constants.xlRight].LineStyle = Excel.XlLineStyle.xlContinuous;

    Anyone know why (1) will work in previous Excel versionsand not in 2007? 

    Why changing to (2) works in 2007?

    BTW, (1) can be used to correctly change xlEdgeLeft on any Excel version. It is only xlEdgeRight, xlEdgeBottom, and xlEdgeTop that will not work in Excel 2007.

    TIA

     

    Thursday, February 08, 2007 9:05 PM

Answers

  • Hi,

    I assume the issue is related to VSTO.

    The following VB procedure does work with both Excel 2003 and Excel 2007:

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    With Me.Range("C2:E10")

    With .Borders(Excel.XlBordersIndex.xlEdgeBottom)

    .LineStyle = Excel.XlLineStyle.xlContinuous

    .ColorIndex = 10

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeTop)

    .LineStyle = Excel.XlLineStyle.xlDash

    .ColorIndex = 5

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeLeft)

    .LineStyle = Excel.XlLineStyle.xlDashDot

    .ColorIndex = 20

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeRight)

    .LineStyle = Excel.XlLineStyle.xlDouble

    .ColorIndex = 8

    End With

    With .Borders(Excel.XlBordersIndex.xlDiagonalDown)

    .LineStyle = Excel.XlLineStyle.xlDashDotDot

    .ColorIndex = 6

    End With

    End With

     

     

     

    Thursday, February 08, 2007 10:49 PM

All replies

  • Hi,

    I assume the issue is related to VSTO.

    The following VB procedure does work with both Excel 2003 and Excel 2007:

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

    With Me.Range("C2:E10")

    With .Borders(Excel.XlBordersIndex.xlEdgeBottom)

    .LineStyle = Excel.XlLineStyle.xlContinuous

    .ColorIndex = 10

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeTop)

    .LineStyle = Excel.XlLineStyle.xlDash

    .ColorIndex = 5

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeLeft)

    .LineStyle = Excel.XlLineStyle.xlDashDot

    .ColorIndex = 20

    End With

    With .Borders(Excel.XlBordersIndex.xlEdgeRight)

    .LineStyle = Excel.XlLineStyle.xlDouble

    .ColorIndex = 8

    End With

    With .Borders(Excel.XlBordersIndex.xlDiagonalDown)

    .LineStyle = Excel.XlLineStyle.xlDashDotDot

    .ColorIndex = 6

    End With

    End With

     

     

     

    Thursday, February 08, 2007 10:49 PM
  • apologies ... this is a COM-Addin using C# and Visual Studio that is not working
    Friday, February 09, 2007 2:19 AM
  • Hi,

    OK - You should post in the following newsgroup:
    http://msdn.microsoft.com/newsgroups/default.aspx?dg=microsoft.public.office.developer.com.add_ins&lang=en&cr=US

    However, the above code works fine for me in a VB managed COM Add-in and with Excel 2007.

    Friday, February 09, 2007 10:16 AM