Hello all,
I have about lost all my hair! I'm trying to format cells in excel from vb. All was going well until I tried to add a border to a selection.
First line works! It selects the row as expected. The other lines I got out of an excel macro(don't work). I get an error message 91bject variable or with block variable not set. The problem doesn't stem from no with statement on the first two lines. You take those out and it still doesn't work.
Any suggestions?
objNewXLBook.ActiveSheet.Range("A" & X + 1 & ":" & "F" & X + 1).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlNone
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
I have about lost all my hair! I'm trying to format cells in excel from vb. All was going well until I tried to add a border to a selection.
First line works! It selects the row as expected. The other lines I got out of an excel macro(don't work). I get an error message 91bject variable or with block variable not set. The problem doesn't stem from no with statement on the first two lines. You take those out and it still doesn't work.
Any suggestions?
objNewXLBook.ActiveSheet.Range("A" & X + 1 & ":" & "F" & X + 1).Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlDiagonalUp)
.LineStyle = xlNone
End With
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With