| 
    
     |  | ▼ichinose さん: >▼まさくん さん:
 >こんばんは。
 >使った事はほとんどありませんが・・・・。
 >>
 >>「DBからデータを取得→エクセルシートに貼り付け」と、いう処理です。
 >>まず、「外部データの取り込み」を下記のマクロにより行いました。
 >>(尚、データ取得1回につき10種類のDBより読み込むため、下記のようなマクロを10種類連続して記述しています)
 >>
 >>With ActiveSheet.QueryTables.Add(Connection:= _
 >>     "OLEDB;Provider=MSDAORA.1;Password=pass;User ID=id;Data
 >>     Source=ORADB", _
 >>     Destination:=Range("A5"))
 >>     .CommandType = xlCmdSql
 >>     .CommandText = Array( _
 >>     "SELECT * FROM OPC.MAKI_PRT_TBL ORDER BY SHOZO_NO ASC,
 >>     SIAGESIJI_NO ASC, LOT_NO ASC,KOMAKI_REEL_NO ASC")
 >>     .Name = "+新しいデータソースへの接続"
 >>     .FieldNames = True
 >>     .RowNumbers = False
 >>     .FillAdjacentFormulas = False
 >>     .PreserveFormatting = True
 >>     .RefreshOnFileOpen = False
 >>     .BackgroundQuery = True
 >>     .RefreshStyle = xlInsertDeleteCells
 >>     .SavePassword = False
 >>     .SaveData = True
 >>     .AdjustColumnWidth = True
 >>     .RefreshPeriod = 0
 >>     .PreserveColumnInfo = True
 >>     .SourceConnectionFile = _
 >>     "C:\Documents and Settings\Administrator\My Documents\My Data
 >>     Sources\ORADB_MAKI_PRT_TBL.odc"
 >>     '.Refresh BackgroundQuery:=True
 >>     .Refresh BackgroundQuery:=False
 >     .delete 'では?
 >>   End With
 >>
 >>ここで、データを取得しシートに貼り付けられたのですが、DBの方にconnectしっぱなしなのです。データを取得しシートに貼り付けたらdisconnectする方法とかあればお教え願います。
 >>現状、エクセルを終了しないとconnectしっぱなしです。。。
 >>(DB制約により、connectしっぱなしだと、他の端末からDBが参照できないのです。。。何せ1回の取得につき10回connectするので困っています)
 
 
 ありがとうございました。
 無事、この方法で解決致しました。
 (返信遅くなり申し訳ないです)
 
 |  |