プロが教えるわが家の防犯対策術!

「セルA10〜印刷設定された最終ページの最右下のセルまで全て格子罫線を引く」というマクロを作りたいのですが、なかなか上手くいきません。どなたかご教示頂けないでしょうか。よろしくお願い致します。

OS:win7
Excel2013

A 回答 (1件)

※ 印刷範囲が設定されていなければ実行しません。



Sub Macro1()
'
' セルA10から印刷範囲の最終ページ最右下セルの範囲で格子罫線を引く
'
Dim startRow As Long
Dim startCol As Long
Dim lastRow As Long
Dim lastCol As Long

If ActiveSheet.PageSetup.PrintArea <> vbNullString Then

With Range(ActiveSheet.PageSetup.PrintArea)
startRow = .Rows.Row
lastRow = startRow + .Rows.Count - 1
startCol = .Columns.Column
lastCol = startCol + .Columns.Count - 1
End With

Range("A10", Cells(lastRow, lastCol)).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

End If

End Sub
    • good
    • 0
この回答へのお礼

ご連絡が遅れて大変申し訳ありませんでした。構文の意味を1つずつ考えながら早速試させていただきます。このたびはお忙しいところ早々のご回答大変ありがとうございました!

お礼日時:2015/12/19 11:02

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!