Добавить линии сетки на лист Excel - PullRequest
0 голосов
/ 23 августа 2011

В приведенном ниже коде, как я могу добавить линии сетки на весь лист 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

Ответы [ 2 ]

4 голосов
/ 23 августа 2011

Это длинный ответ (код Excel VBA генерирует при записи макроса). Вы можете определенно сократить это. Например, вам не нужно устанавливать свойства .ColorIndex или .TintAndShade, чтобы сделать стандартный черный [править] border .

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

EDIT

Для линий сетки:

ActiveWindow.DisplayGridlines = True

Вы также можете использовать:

Windows(1).DisplayGridlines = True
3 голосов
/ 23 августа 2011

Попробуйте это:

ActiveWindow.DisplayGridlines = True

Это должно включить линии сетки. И, конечно, установка свойства False отключит их.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...