'SQL*Plusで実行 ver.1.03 'EmEditor version7.00以降で動作します '現在開いているSQL文を起動済みのSQLPlusで実行するマクロです。 '文字列を選択した状態で実行するとSQL*Plusにコピー&ペーストします。 '貼り付けに失敗する場合はSleepTimeを増やす方向で調整してください。 '2006/12/03 ver.1.00 'サクラエディタっぽく動くようにしてみた '2006/12/19 ver.1.01 '初回に失敗することがあるためファイル名貼り付け方法を変更 '2007/02/04 ver.1.02 '選択状態で実行したら選択文字列を貼り付けるようにした。 '2010/01/18 ver.1.03 'EmEditorからshellオブジェクトが利用出来るようになったためMS-Word 'のオブジェクトを使わないように変更。 'コマンドプロンプトからのsqlplusも検索できるようにしました。貼り付け '動作はこっちの方が速いです。 '1秒待つ。貼り付けに失敗する場合はここを増やす。 SleepTime = 1000 'SQL*PLusを探す bFind = False bCmd = False For Each wnd In shell.windows If (wnd.Caption = "Oracle SQL*Plus") Then bFind = True bCmd = False Exit For ElseIf (Lcase(Left(wnd.Caption,20)) = "コマンド プロンプト - sqlplus") _ Or (Instr(Lcase(wnd.Caption),"cmd.exe - sqlplus") > 0) Then bFind = True bCmd = True Exit For End If Next If Not bFind = True Then alert("SQL*Plusを起動してください") Quit End If '文字列が選択されているか If document.selection.IsEmpty Then '選択していない場合ファイルに保存されていないと実行できない If Not document.Saved Then If confirm("文書が保存されていません。保存しますか?") Then document.Save document.FullName Else Quit End If End If 'コマンドプロンプト If (bCmd = True) Then 'クリップボード(unicode,oemtext)にコピー clipboardData,setData "Text", "@""" & document.FullName & """" & vbCrLf Call SendSQL (wnd,null,SleepTime,bCmd) Else 'ファイル名をクリップボード(text)へコピー document.CopyFullName Call SendSQL (wnd,"@""^V""~", SleepTime,bCmd) End If Else '選択文字列をSQL*Plusに貼り付け Call ExecSel(wnd,SleepTime,bCmd) End If '終了 Quit '----------------------------- ' 選択した部分のSQLを実行する '----------------------------- Sub ExecSel(wnd,SleepTime,bCmd) Dim sqlLen,maxLen,i,cnt,ModeLine '選択モードが行選択か If document.selection.Mode And eeModeLine Then ModeLine = True Else ModeLine = False End If 'SQL*Pluswは大きいサイズの文字列貼り付けに対応できない(3000バイト程度まで) maxLen = 1500 'これは最大文字数 strSQL = Replace(document.selection.text, vbcr, "") sqlLen = Len(strSQL) '1回で貼り付けできるサイズか If (sqlLen < maxLen) Or (bCmd = True) Then document.selection.Copy eeCopyUnicode 'クリップボードへコピー '選択モードが行選択だと改行も選択されているのでEnterキーは送信しない If ModeLine = True Then Call SendSQL (wnd, "^V", SleepTime, bCmd) '貼り付け Else Call SendSQL (wnd, "^V~", SleepTime, bCmd) '貼り付け+Enter End If Else '選択文字列のサイズが大きいときは分割して貼り付け xPos = document.selection.GetAnchorPointX (eePosLogicalA) '選択開始位置X yPos = document.selection.GetAnchorPointY (eePosLogical) '選択開始位置Y i = 0 Do If i + maxLen >= sqlLen Then cnt = sqlLen - i '選択文字列最後 Else cnt = maxLen '最大文字数分だけ貼り付け End If document.selection.Collapse '選択解除 document.selection.SetActivePoint eePosLogicalA, xPos, yPos 'キャレット位置設定 document.selection.SetAnchorPoint eePosLogicalA, xPos, yPos '選択開始位置設定 document.selection.CharRight True, cnt 'キャレット移動 document.selection.Copy eeCopyUnicode 'クリップボードへコピー xPos = document.selection.GetBottomPointX (eePosLogicalA) '選択終了位置X yPos = document.selection.GetBottomPointY (eePosLogical) '選択終了位置Y Call SendSQL(wnd, "^V", SleepTime, bCmd) '貼り付けコマンド送信 i = i + cnt Loop Until i >= sqlLen '行選択でなかったらEnterキー送信 If Not ModeLine = True Then Call SendSQL(wnd, "~", SleepTime, bCmd) End If '選択解除 document.selection.Collapse End If End Sub '----------------------------- ' 選択した部分のSQLを実行する '----------------------------- Sub SendSQL(wnd, strKey, SleepTime, bCmd) wnd.SetForeground 'SQL*Plusを前面にする Sleep SleepTime '少し待つ If (bCmd = True) Then 'コマンドプロンプト shell.SendKeys "{CLICK RIGHT, " & wnd.LeftX + 100 & "," & wnd.Top + 100 & "}P" Else shell.SendKeys strKey '[貼り付けコマンド|Enter] Sleep SleepTime '少し待つ End If End Sub