TOP をテンプレートにして作成
ホーム
バックアップ
一覧
検索
最終更新
ヘルプ
ログイン
開始行
--[[プログラミングガイド]]~
*Excel VBAサンプル(ADO、ODBC) [#e60e3d09]
※要ODBCドライバインストール
+エクセルのブックを新規作成
+メニューバーから「ツール」−「マクロ」−「Visual Basic Edi...
+Visual Basic Editorのメニューバーから「ツール」−「参照設...
+参照設定ウィンドウで「Microsoft ActiveX Data Objects x.x...
+↓のソースを貼り付け実行(SQLやDBのパスは適当に変更)
Sub hoge()
Dim con As ADODB.Connection
Dim recordSet As ADODB.recordSet
Dim outPutSheet As Worksheet
Dim row As Long
Dim col As Long
Set con = New ADODB.Connection
Set recordSet = New ADODB.recordSet
Set outPutSheet = ThisWorkbook.Sheets("Sheet1") '出力...
outPutSheet.Cells.Clear
'DB接続とデータ取得
con.Open "DRIVER=Firebird/InterBase(r) driver; SERVER...
"UID=sysdba; PWD=masterkey;Client=C:\Program...
recordSet.Open "select * from rdb$database", con, adO...
'データ展開
For col = 0 To recordSet.Fields.Count - 1
outPutSheet.Cells(1, col + 1).Value = recordSet.F...
Next col
row = 2
While (Not recordSet.EOF) And row < 60000
For col = 0 To recordSet.Fields.Count - 1
outPutSheet.Cells(row, col + 1).Value = recor...
Next col
recordSet.MoveNext
row = row + 1
Wend
'終了処理
recordSet.Close
con.Close
If row > 60000 Then
MsgBox "60000行を超えたため中断しました"
Else
MsgBox "出力が終了しました"
End If
End Sub
最終行:
--[[プログラミングガイド]]~
*Excel VBAサンプル(ADO、ODBC) [#e60e3d09]
※要ODBCドライバインストール
+エクセルのブックを新規作成
+メニューバーから「ツール」−「マクロ」−「Visual Basic Edi...
+Visual Basic Editorのメニューバーから「ツール」−「参照設...
+参照設定ウィンドウで「Microsoft ActiveX Data Objects x.x...
+↓のソースを貼り付け実行(SQLやDBのパスは適当に変更)
Sub hoge()
Dim con As ADODB.Connection
Dim recordSet As ADODB.recordSet
Dim outPutSheet As Worksheet
Dim row As Long
Dim col As Long
Set con = New ADODB.Connection
Set recordSet = New ADODB.recordSet
Set outPutSheet = ThisWorkbook.Sheets("Sheet1") '出力...
outPutSheet.Cells.Clear
'DB接続とデータ取得
con.Open "DRIVER=Firebird/InterBase(r) driver; SERVER...
"UID=sysdba; PWD=masterkey;Client=C:\Program...
recordSet.Open "select * from rdb$database", con, adO...
'データ展開
For col = 0 To recordSet.Fields.Count - 1
outPutSheet.Cells(1, col + 1).Value = recordSet.F...
Next col
row = 2
While (Not recordSet.EOF) And row < 60000
For col = 0 To recordSet.Fields.Count - 1
outPutSheet.Cells(row, col + 1).Value = recor...
Next col
recordSet.MoveNext
row = row + 1
Wend
'終了処理
recordSet.Close
con.Close
If row > 60000 Then
MsgBox "60000行を超えたため中断しました"
Else
MsgBox "出力が終了しました"
End If
End Sub
ページ名:
新規
名前変更
ホーム
一覧
検索
最終更新
バックアップ
ヘルプ
最終更新のRSS