タイトル | : Re^5: VB2005からAccess2000への連携時のトラブル |
記事No | : 7740 |
投稿日 | : 2008/06/27(Fri) 10:03 |
投稿者 | : kiRITYAN |
解放処理出来ました。ありがとうございます。 下の処理です。No.7734 のコードでデータを抽出した後したの標準モジュールを読みだしています。 Excel_Write_Open Excel_Write_Main Excel_Write_Close ← 30回くらい繰り返し Excel_Write_End このようにしたのは他の処理でも使いまわししたいからです。
Dim Excel_App As New Excel.Application Dim Excel_Books As Excel.Workbooks Dim Excel_Book As Excel.Workbook Dim Excel_Sheets As Excel.Sheets Dim Excel_Sheet As Excel.Worksheet
Public Function Excel_Write_Open(ByVal Excel_Open_File_Pass As String, ByVal Excel_Open_Sheet As Integer) As Boolean Try Excel_Books = Excel_App.Workbooks If Excel_Open_File_Pass = "" Then '新規ファイルを開く Excel_Book = Excel_Books.Add Else '既存のファイルを開く Excel_Book = Excel_Books.Open(Excel_Open_File_Pass) End If Excel_Sheets = Excel_Book.Worksheets Excel_Sheet = Excel_Sheets.Item(Excel_Open_Sheet) 'Sheet1を選択 Excel_Write_Open = True Catch Err As Exception MessageBox.Show(Err.Message & "Err", "警告", MessageBoxButtons.OK) Excel_Write_Open = False End Try End Function '****************************************************************************** '* OpenされたExcelのセルに値を代入する '****************************************************************************** Public Function Excel_Write_Main(ByVal Excel_Place As String, ByVal Excel_Value As String) As Boolean Try Excel_Sheet.Range(Excel_Place).Value = Excel_Value Excel_Write_Main = True Catch Err As Exception MessageBox.Show(Err.Message & "Err", "警告", MessageBoxButtons.OK) Excel_Write_Main = False End Try End Function '****************************************************************************** '* Excelの終了と保存 '****************************************************************************** Public Function Excel_Write_Close(ByVal Excel_Close_File_Pass As String) As Boolean Try Excel_App.DisplayAlerts = False '保存時の問合せのダイアログを非表示 If Excel_Close_File_Pass <> "" Then Excel_Sheet.SaveAs(Excel_Close_File_Pass) 'ファイルに保存 End If Excel_App.DisplayAlerts = True '問い合わせ設定を元に戻す
MRComObject(Excel_Sheet) 'Sheet の解放 MRComObject(Excel_Sheets) 'Sheets の解放 Excel_Book.Close(False) 'Book を閉じる MRComObject(Excel_Book) 'Book の解放 MRComObject(Excel_Books) 'Books の解放 Excel_App.Quit() 'Excelを閉じる Excel_Write_Close = True Catch Err As Exception MessageBox.Show( "失敗", "警告", MessageBoxButtons.OK) Excel_Write_Close = False End Try End Function '****************************************************************************** '* Excelを開放する '****************************************************************************** Public Function Excel_Write_End() As Boolean Try Close_Com_Object(Excel_App) 'Appを開放する Excel_Write_End = True Catch Err As Exception MessageBox.Show( "Err", "警告", MessageBoxButtons.OK) Excel_Write_End = False End Try End Function
|