« [VB6.0] 文字列バイトチェック | メイン | [VB6.0] 配列重複チェック »

2005年09月29日

[VB6.0] Excelの操作

'-----------------------------------------------------------
' ■ 既存のExcelファイルを開く
'-----------------------------------------------------------

Dim xlApp As Excel.Application
Dim XlBook As Excel.Workbook
Dim XlSheet As Excel.Worksheet


'--- Excel設定
Set xlApp = CreateObject("Excel.Application")
Set XlBook = xlApp.Workbooks.Open("開きたいExcelのパス")
Set XlSheet = XlBook.Worksheets("シート名")

'エラー音の設定
xlApp.DisplayAlerts = True


'アプリケーションの表示・非表示
xlApp.Visible = True


'Excelの処理
With XlSheet

'セルの指定
.Cells(Row, Col) = "値"

'複数セルの指定(セル(1,1)〜セル(Row,Col)の範囲)
.Range(.Cells(1, 1), .Cells(Row, Col)) = "配列名"

'シングルクォーテーションを引っ掛ける(VBA?)
.Cells(Row, Col).PrefixCharacter

End With

'--- Excel解放
Set XlSheet = Nothing
XlBook.Close
Set XlBook = Nothing
xlApp.Quit
Set xlApp = Nothing

2005 / 09 / 29