対象のセル、または行・列を指定し、罫線を描画する処理です。
ここでは、シート1の7行目を全選択し、選択部分の下部に罫線を描画しています。
' Excelアプリケーション Dim xlApp As Application = Nothing ' ワークブック Dim xlBooks As Workbooks = Nothing Dim xlBook As Workbook = Nothing ' シート Dim xlSheets As Sheets = Nothing Dim xlSheet As Worksheet = Nothing ' セル Dim xlRngTmp As Range = Nothing Dim xlRng As Range = Nothing ' セル境界線(枠) Dim xlBorders As Borders = Nothing Dim xlBorder As Border = Nothing ' Excelを開く xlApp = New Application xlApp.DisplayAlerts = False xlBooks = xlApp.Workbooks xlBook = xlBooks.Open("対象Excelまでのパス") xlSheets = xlBook.Worksheets xlSheet = DirectCast(xlSheets(1), Worksheet) ' 1シート目を操作対象に設定 ' 行7全体のオブジェクトを作成 xlRngTmp = xlSheet.Rows xlRng = xlRngTmp(7) ' 境界線オブジェクトを作成 →7行目の下部に罫線を描画する xlBorders = xlRngTmp.Borders xlBorder = xlBorders(XlBordersIndex.xlEdgeBottom) xlBorder.LineStyle = XlLineStyle.xlContinuous ' Excelを表示して3秒間表示 xlApp.Visible = True System.Threading.Thread.Sleep(3000) ' ■■■以下、COMオブジェクトの解放■■■ ' レンジ解放 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorder) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBorders) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRng) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlRngTmp) ' Sheetのクローズ処理 System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets) ' Excelのクローズ処理 xlBook.Close() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks) ' アラートを戻す xlApp.DisplayAlerts = True ' ExcelApplicationを閉じる xlApp.Quit() System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApp) '
※ COMオブジェクトの解放をまとめたい方は、こちらでメソッドの紹介をしています。