タイトル : Re^8: Excelとの連携 投稿日 : 2008/01/23(Wed) 16:44 投稿者 : たー
> > > 今の所解決方法が分かっていませんが,報告させていただきました。 > > 単に変数の宣言している場所が間違っているだけですが。 > > クリックした時点で変数を宣言しているので、いつも 0 からのスタートです。 > > Private で宣言して見て下さい。 ご指摘ありがとうございます。 おかげさまで以下のソースで+1されて次を読み込むプログラムができました。 あと一つ疑問なんですが 最初の読み込みを 3 から始めたいのですが i = 3 は何処で宣言したいいのですか? これも Command1_Click()の中で宣言したらだめですよね? Private i As Integer Private Sub Command1_Click() Dim xlApp As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet Set xlApp = CreateObject("Excel.Application") Set xlBook = xlApp.Workbooks.Open("test.xls") Set xlSheet = xlBook.Worksheets(1) Dim xlCells As Excel.Range Set xlCells = xlSheet.Cells '--------------- エクセルの表をVBへ読み込み ------------------- i = i + 1 Text1.Text = xlCells(i, 2).Value Text2.Text = xlCells(i, 3).Value Text3.Text = xlCells(i, 4).Value Text4.Text = xlCells(i, 5).Value '================================================================== '終了処理 Set xlCells = Nothing Set xlSheet = Nothing xlBook.Close 'Book を閉じる Set xlBook = Nothing xlApp.Quit Set xlApp = Nothing End Sub |