Hello,

I want to display an Excel file in a userform in vb.net. I realized
this by using the "Browser" Component as described in Microsofts KB an
it works good.

Now I want to edit the Excel sheet displayed in the webbrowser
component.
How can I get access to the already running Excel Application?
I found an example like this:

Private Function GetActiveWorkbook(ByVal _strFileName As String) As
Excel.Workbook
Dim pRot As IRunningObjectTable = Nothing
Dim pMonikerEnum As IEnumMoniker = Nothing

Try
'Running object table (ROT) erstellen
GetRunningObjectTable(0, pRot)
If pRot Is Nothing Then
Return Nothing
End If

'pRot in pMinokerEnum laden
pRot.EnumRunning(pMonikerEnum)
pMonikerEnum.Reset()

Dim monikers() As IMoniker = New IMoniker(0) {}

While (pMonikerEnum.Next(1, monikers, IntPtr.Zero) = 0)
Dim pCtx As IBindCtx = Nothing
Dim strDisplayName As String = String.Empty

CreateBindCtx(0, pCtx)
monikers(0).GetDisplayName(pCtx, Nothing,
strDisplayName)
Marshal.ReleaseComObject(pCtx)

If (strDisplayName.Contains(_strFileName) = True)
Then
Dim objWorkbookHandle As Object = Nothing
' Get a handle on the workbook
pRot.GetObject(monikers(0), objWorkbookHandle)
Return CType(objWorkbookHandle, Excel.Workbook)
'Return objWorkbookHandle
End If

End While
Catch
Return Nothing
Finally
If (Not (pRot) Is Nothing) Then
Marshal.ReleaseComObject(pRot)
End If
If (Not (pMonikerEnum) Is Nothing) Then
Marshal.ReleaseComObject(pMonikerEnum)
End If
End Try
Return Nothing
End Function


Function AttachApplication() As Excel.Application
Try
' Workbook
xlsWebWorkbook = GetActiveWorkbook(filename)
If (xlsWebWorkbook Is Nothing) Then
Return Nothing
End If

' Excel Application
xlsWebApplication = xlsWebWorkbook.Application

Return xlsWebApplication

Catch
MessageBox.Show("Excel error")
Return Nothing
End Try

End Function

this works also very good BUT,

if my vb.net application is running and the a excelfile is opend in it
and the application is assigend to the running excel process and then i
would open a other excel file in normal excel it wont work.
sometimes the excel in the vb. net app is freezing an the "new" excel
works on or the "new" excel freezes an the .net app works fine.

I couldnt find a solution for this problem so i tried to ask here.
Thank you very mutch for helping an posting.

regards Jo