The below does not work. How do I add borders? Thanks!
Set objApp = CreateObject("Excel.Application")
objApp.Visible = True
Set wb = objApp.Workbooks.Open("aFile.xls", True, False)
objApp.Cells.Select
objApp.Selection.Borders(xlDiagonalDown).LineStyle = xlNone
objApp.Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With objApp.Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objApp.Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objApp.Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objApp.Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objApp.Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
With objApp.Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.ColorIndex = 0
.TintAndShade = 0
.Weight = xlThin
End With
Set objApp = Nothing
The VBA code did not work for me so I discovered a workaround. Since I was using an Excel template to create the Excel sheet. I modified the Excel template to print Gridlines.
To enable Gridlines to Print:
Excel > Print Preview > Page Setup > Sheet > Check mark gridlines under Print.