1

I am using a macro when outlook opens to insert some data from an email, into a row in excel, I want to add a border to the range in my excel row A to AE.

I am using intRow4 to determine the row address where my information is being entered. so my code looks like this, but I am getting an object undefined error on Dim Rng As Range because I get the feeling outlook doesn't support it.

Const SHEET_NAME4 = "Statistics"
excWks4 As Object, _
intRow4 As Integer, _
Set excWks4 = excWkb.Worksheets(SHEET_NAME4)
intRow4 = excWks4.UsedRange.Rows.Count + 1



Dim Rng As Range

    Set Rng = ws2.Range("A" & intRow4 & ":AE" & intRow4 & "")

    With Rng.Borders
        .LineStyle = xlContinuous
        .Color = vbBlack
        .Weight = xlThin
    End With

can someone please show me where I am going wrong with this? Thank you

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
james daley
  • 47
  • 1
  • 3
  • 9
  • Also do not use `intRow4 = excWks4.UsedRange.Rows.Count + 1` You might get unexpected results and end up creating borders where not required. Use [this](http://stackoverflow.com/questions/11169445/error-finding-last-used-cell-in-vba) method to find the last row – Siddharth Rout Nov 10 '14 at 11:41

1 Answers1

0

xlContinuous, vbBlack and xlThin are Excel constants. Outlook will not recognize them if you are using late binding. Add this to the top of your code.

Const xlContinuous As Integer = 1
Const vbBlack As Integer = 0
Const xlThin As Integer = 2

Also if you are using Last Binding then change Dim Rng As Range to Dim Rng As Object

Siddharth Rout
  • 147,039
  • 17
  • 206
  • 250