ExcelオートメーションでDDE要求を無視する。(その2)
Excelオートメーションで処理しているときに、Excelファイルを関連付けで開いたり、印刷すると、Excelオートメーションの処理中にDDE要求が入って来て、困ります。
なので、Excelオートメーションの処理中は「他のアプリケーションを無視する」とよいでしょう。ただし、「他のアプリケーションを無視する」のは、そのオートメーション処理中のExcelだけで、他のExcelの設定を変えないようにするには若干コツが必要です。
Set Application=CreateObject("Excel.Application")
の代わりに、
Set Application=GetApplication()
とします。
以下のVBSファイルは、そういうExcelを起こして、ブックを開きます。
IgnoreRemoteRequests.VBS [ブック...]
Option Explicit
Dim Application
Dim Arg
Set Application=GetApplication()
Application.Visible=True
Application.UserControl=True
For Each Arg In WScript.Arguments
Application.WorkBooks.Open Arg
Next
Function GetApplication()
Dim wShell
Dim CurVer
Dim Key
Dim Options
Set wShell=CreateObject("WScript.Shell")
CurVer=wShell.RegRead("HKEY_CLASSES_ROOT\Excel.Application\CurVer\")
CurVer=Mid(CurVer,InStrRev(CurVer,".")+1)
Key="HKEY_CURRENT_USER\Software\Microsoft\Office\" & CurVer & ".0\Excel\Options\Options"
Options=wShell.RegRead(Key)
If Options And &H40 Then wShell.RegWrite Key,Options Xor &H40,"REG_DWORD"
Set GetApplication=CreateObject("Excel.Application")
If Options And &H40 Then wShell.RegWrite Key,Options,"REG_DWORD"
End Function
« HTMLページのプロパティからURLを新ウィンドウに開き直す。 | トップページ | Explorer.exeを起こして、そのエクスプローラのオブジェクトを正確に捕捉する。(VBA編) »