ElieAintabi
New member
- Joined
- Oct 6, 2008
- Messages
- 3
- Programming Experience
- 1-3
Excel.Application / RunningObjectTable
I have a project where I create a new Excel.Application (version 11) and write to it. The problem is, after creating the excel.application if a user tries to open a previously saved Excel file (from their desktop for instance) then my excel.application's visibility is set to true automatically, which reveals my table and I do not want that.
I was told this is because my excel.application is the first entry in the RunningObjectTable, so my question is how do I implement RevokeActiveObject to get my object out of the ROT if I never used RegisterActiveObject?
I have a project where I create a new Excel.Application (version 11) and write to it. The problem is, after creating the excel.application if a user tries to open a previously saved Excel file (from their desktop for instance) then my excel.application's visibility is set to true automatically, which reveals my table and I do not want that.
I was told this is because my excel.application is the first entry in the RunningObjectTable, so my question is how do I implement RevokeActiveObject to get my object out of the ROT if I never used RegisterActiveObject?
VB.NET:
Option Explicit On
Imports System.Runtime.InteropServices.ComTypes
Module Module1
Private Declare Function CreateBindCtx Lib "ole32" ( _
ByVal dwReserved As Integer, ByRef pBindCtx As IBindCtx) As Integer
Private Declare Sub RevokeActiveObject Lib "oleaut32" ( _
ByVal dwregister As Long, ByRef pvReserved As Long)
Private Declare Unicode Function CLSIDFromProgID Lib "ole32" ( _
ByVal lpszProgId As String, ByRef pclsid As Guid) As Integer
public sub test()
Dim excelObj As New Microsoft.Office.Interop.Excel.Application
excelObj.Workbooks.Add()
excelObj.Workbooks(1).Worksheets.Add()
excelObj.Workbooks(1).Worksheets(1).Cells(1, 1) = "a"
...
Dim bindctx As IBindCtx
CreateBindCtx(0, bindctx)
Dim clsid As Guid
Dim hresult As Integer = CLSIDFromProgID("Excel.Application", clsid)
Dim pprot As IRunningObjectTable
bindctx.GetRunningObjectTable(pprot)
Dim ppenumMoniker As IEnumMoniker
pprot.EnumRunning(ppenumMoniker)
Dim rgelt(0) As IMoniker
Dim pceltFetched As Integer
Do While ppenumMoniker.Next(rgelt.Length, rgelt, pceltFetched) = 0
Dim ppszDisplayName As String
rgelt(0).GetDisplayName(bindctx, Nothing, ppszDisplayName)
If (ppszDisplayName = "Book2" Or ppszDisplayName = "Book1") Then
'RemoveActiveObject(excelObj, vnROTID)
Console.WriteLine("var is {0}", excelObj.ToString)
Console.WriteLine("guid of excel is {0}", clsid.ToString("B").ToUpper())
End If
Loop
'excelObj.Visible = True
End Sub