Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 40
Default 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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesn't While ActiveWorkBook < Null work? [email protected] Excel Discussion (Misc queries) 3 May 27th 07 12:05 AM
ActiveWorkbook.Protect password:=range("rangename") does not work WimR Excel Discussion (Misc queries) 1 June 26th 05 08:47 AM
Workbook container - can't get it to work Ken Valenti Excel Programming 0 March 14th 05 07:59 PM
Container property Stewart Walker Excel Programming 0 May 28th 04 10:28 AM
protect module and work in activeworkbook Mark[_17_] Excel Programming 3 September 28th 03 10:43 PM


All times are GMT +1. The time now is 01:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"