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


関連記事

サンフランシスコのピア39にあるチャウダーズでクラムチャウダーを食す!

lolipop アップルの開発者向けイベント「WWDC2014」

ミスドのカルピスドーナツとカルピスポンデリングを食べてみた!

ミスドで期間限定のカルピスコラボ商品「カルピスドーナツ」と「カルピ

十三カレー計画で牛すじカレーネギのせを食す!(大阪・十三)

「iPhoneアプリ開発キャンプ@大阪」のランチで、十三カレー計画

大阪・難波の加寿屋 法善寺でかすうどんを食す。ランチタイムはおにぎり2個まで無料!

大阪・難波の加寿屋 法善寺 (かすうどん KASUYA)で、かす

ライブドアブログで運営していた「あきお商店」を「卵は世界である」に改名しました

少し前からライブドアブログで「あきお商店」というブログをやって

→もっと見る

PAGE TOP ↑