View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
K Dales[_2_] K Dales[_2_] is offline
external usenet poster
 
Posts: 1,163
Default Can't get ActiveWorkbook.Container to work

Just read your prior post. Note that in the code you included there is a
test for the error condition created by calling ActiveWorkbook.Container when
in Excel:
Sub CheckIfInInternetExplorer()
Dim x As Object
'Try to get container object
' NEXT LINE SAYS, "IGNORE ERROR"
On Error Resume Next
Set x = ActiveWorkbook.Container
' NEXT LINE TURNS ERROR CHECKING BACK ON
On Error GoTo 0

'Show result depending on container's typename
Select Case TypeName(x)
'NOTE: IF TypeName is "Nothing", it implies no TypeName found; i.e. there is
no container other than Excel:
Case "Nothing"
MsgBox "The workbook is opened in Excel"
Case "IWebBrowser2"
MsgBox "The workbook is opened in Internet Explorer"
Case Else
MsgBox "The workbook is opened in another application: " & TypeName(x)
End Select
End Sub


"K Dales" wrote:

Is it failing under all circumstances, or only when opened in Excel?
"If the container doesnt support OLE Automation or the workbook isnt
embedded, this property fails"
So ActiveWorkbook.Container will error out if you try it for a book open
within Excel, but it should work properly if the book is open (embedded) in
your browser.

"Ken Valenti" wrote:

I need to know if my workbook opens in a browser or Excel application.

I cannot get ActiveWorkbook.Container to work. I've tried on 4 machines and
3 versions of excel (97, 2000 & 2003).

This errors out - Any ideas?

sub TestIt()
msgbox ActiveWorkbook.Container
end sub