タイトル | : Re: VB.NETからエクセルでの2箇所のセル選択 |
記事No | : 2151 |
投稿日 | : 2005/09/16(Fri) 17:42 |
投稿者 | : なおこ(・∀・) |
お世話になります。
とりあえず、unionはこんな感じですかねぇ。 Public Sub uniontest(ByVal excel_path As String)
Dim objXlsApp As Excel.Application = New Excel.Application Dim objXlsBooks As Excel.Workbooks = objXlsApp.Workbooks Dim objXlsBook As Excel.Workbook Dim objXlsSheets As Excel.Sheets Dim objXlsSheet As Excel.Worksheet Dim objXlsRange1 As Excel.Range Dim objXlsRange2 As Excel.Range Dim rngDataRange As Excel.Range Try
objXlsBook = objXlsBooks.Open(excel_path, , False) objXlsSheets = objXlsBook.Worksheets objXlsSheet = CType(objXlsSheets.Item(1), Excel.Worksheet)
objXlsRange1 = CType(objXlsSheet.Cells(1, 5), Excel.Range) objXlsRange2 = CType(objXlsSheet.Cells(3, 5), Excel.Range) rngDataRange = objXlsApp.Union(objXlsRange1, objXlsRange2)
Catch ex As Exception Throw ex Finally Try System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsRange1) System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsRange2) System.Runtime.InteropServices.Marshal.ReleaseComObject(rngDataRange) System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsSheet) System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsSheets) If Not IsNothing(objXlsBook) Then objXlsBook.Close(False) End If System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsBook) System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsBooks) If Not IsNothing(objXlsApp) Then objXlsApp.Quit() End If System.Runtime.InteropServices.Marshal.ReleaseComObject(objXlsApp) Catch ex As Exception End Try End Try End Sub
|