Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Why doesn't While ActiveWorkBook < Null work? | Excel Discussion (Misc queries) | |||
ActiveWorkbook.Protect password:=range("rangename") does not work | Excel Discussion (Misc queries) | |||
Workbook container - can't get it to work | Excel Programming | |||
Container property | Excel Programming | |||
protect module and work in activeworkbook | Excel Programming |