We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Broders in Excel

terencebeh asked
Medium Priority
Last Modified: 2010-04-30
How do I set the borders in Excel(Office 95)?

I was trying the following code but just couldn't get it working.

ExcelApp.ActiveWorkbook.ActiveSheet.Range("C13:I13").Borders(xlBottom).LineStyle = xlDot
    ExcelApp.ActiveWorkbook.ActiveSheet.Range("C13:I13").Borders(xlTop).Weight = xlThin

Error message is : 1004 : Border method of Range class failed.

Please help. Thanks.
Watch Question

The easiest way is to record a macro.  Tools, macro, record macro.  Then go to tools, macro, select the macro and then select edit.  There is your code you can add to it from there.  This is the prefered way to design macros in excel.

After you do this, you copy the code to the visual basic module after you select the appropriate object (get object, openworkbook, ect)(but thats pretty obvious)

Good luck


That's exactly what I did. But it doesn't work.
Here is code from a project I have that works, the Excel object
I created is named InvForm

InvForm.Application.Cells(x + 19, 6).Value = cTotal
InvForm.Application.Cells(x + 19, 6).BorderAround _
Weight:=xlThin, ColorIndex:=xlAutomatic

Also, I had used the same method that SPECIALIST mentioned,
that's the easiest way I know of finding out how to do something.
I'd give him the points.

.Worksheets(1).Range("J2").Borders.LineStyle = xlContinuous
Worksheets(1).Range("J2").Borders.ColorIndex = xlAutomatic

it should be something like that


That's what exactly I do. I am suspecting that the version of
Microsoft Excel 5.0 Object Library file is the cause of this.
Can some of you check the date/size of this file : xl5en32.olb?

Are you using
ExcelApp.ActiveWorkbook.ActiveSheet.Range("C13:I13").BorderAround...? or
Borders collection only has properties.
you need to use the .BorderAround Method

I guess I should mention, depending on what method you are using to do this, you may or may not have to modify the code.  For example, It depends on whether you use the getobject, open workbook etc.  If you use  Workbooks.Open filename:="nameandpath", you should be able to post the code without modification.

If you use Getobject, you may have to modify certain aspects of the code.

Let me know, post your full code if this doesn't help.


Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.