ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can't get ActiveWorkbook.Container to work (https://www.excelbanter.com/excel-programming/325446-cant-get-activeworkbook-container-work.html)

Ken Valenti

Can't get ActiveWorkbook.Container to work
 
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

K Dales[_2_]

Can't get ActiveWorkbook.Container to work
 
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


K Dales[_2_]

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


Ken Valenti

Can't get ActiveWorkbook.Container to work
 
Thanks - that helped me solve the issues.

The other issue was that this does not work in the Workbook_Open event.

Thanks for your help.

Ken

"K Dales" wrote:

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



All times are GMT +1. The time now is 12:33 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com