将网格线添加到Excel工作表
在下面的代码中,如何将网格线添加到整个Excel工作表?
Set objApp = CreateObject("Excel.Application") objApp.Visible = True Set wb = objApp.Workbooks.Open("template.xls", True, False) wb.Sheets(1).Rows(3).Delete wb.Sheets(1).Range("A1").Value = title 'need to format column E & F as currency Set objApp = Nothing
这是一个很长的回答(Excel VBA在录制macros时生成的代码)。 你绝对可以缩短这一点。 例如,您不需要设置.ColorIndex或.TintAndShade属性只是为了做一个标准的黑色边框 。
Cells.Select Selection.Borders(xlDiagonalDown).LineStyle = xlNone Selection.Borders(xlDiagonalUp).LineStyle = xlNone With Selection.Borders(xlEdgeLeft) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeTop) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlEdgeRight) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideVertical) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With With Selection.Borders(xlInsideHorizontal) .LineStyle = xlContinuous .ColorIndex = 0 .TintAndShade = 0 .Weight = xlThin End With
编辑
对于网格线:
ActiveWindow.DisplayGridlines = True
你也可以使用:
Windows(1).DisplayGridlines = True
尝试这个:
ActiveWindow.DisplayGridlines = True
这应该打开网格线。 而且,当然,将该物业设置为False
会将其closures。