VB.NET2003からExcel2000を制御するコード
公開日:
:
最終更新日:2014/01/28
プログラミング
記事内に広告を含む場合があります。記事内で紹介する商品を購入することで、当サイトに売り上げの一部が還元されることがあります。
Dim xlApplication As Excel.Application
Try
xlApplication = New Excel.Application
xlApplication.DisplayAlerts = False
Dim xlBooks As Excel.Workbooks = xlApplication.Workbooks
Try
Dim xlBook As Excel.Workbook = xlBooks.Add()
Try
Dim xlSheets As Excel.Sheets = xlBook.Worksheets
Try
Dim xlSheet As Excel.Worksheet = DirectCast(xlSheets(1), Excel.Worksheet)
Try
xlApplication.Visible = True
xlApplication.Range("A2").Select()
xlApplication.ActiveCell.FormulaR1C1 = "Hello"
xlApplication.Range("B2").Select()
xlApplication.ActiveCell.FormulaR1C1 = "World"
Finally
If Not xlSheet Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheet)
End If
End Try
Finally
If Not xlSheets Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlSheets)
End If
End Try
Finally
If Not xlBook Is Nothing Then
Try
xlBook.Close()
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBook)
End Try
End If
End Try
Finally
If Not xlBooks Is Nothing Then
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlBooks)
End If
End Try
Catch ex As Exception
MsgBox(ex.Message)
Finally
If Not xlApplication Is Nothing Then
Try
xlApplication.Quit()
Finally
System.Runtime.InteropServices.Marshal.ReleaseComObject(xlApplication)
End Try
End If
End Try