![]() |
How to tell if Excel is in Browser or Application
I have a website with a hyperlink to an Excel spreadsheet. Some computers
are setup so that Excel opens in a browser, others open in the Excel application. I need to know if Excel is in a browser or not - since most of my macros don't work in a browser. Is there code to know if this? It has to work with Excel 97 through 2003. I'm thinking if there is something that errors out when in a browser, I could catch that error and know that way. Any insight is appreciated. |
How to tell if Excel is in Browser or Application
This is a routine posted by Ture Magnusson that may may give you some ideas:
Sub CheckIfInInternetExplorer() Dim x As Object 'Try to get container object On Error Resume Next Set x = ActiveWorkbook.Container On Error GoTo 0 'Show result depending on container's typename Select Case TypeName(x) 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 -- Jim Rech Excel MVP "Ken Valenti" <Ken wrote in message ... |I have a website with a hyperlink to an Excel spreadsheet. Some computers | are setup so that Excel opens in a browser, others open in the Excel | application. I need to know if Excel is in a browser or not - since most of | my macros don't work in a browser. | | Is there code to know if this? It has to work with Excel 97 through 2003. | I'm thinking if there is something that errors out when in a browser, I could | catch that error and know that way. | | Any insight is appreciated. |
How to tell if Excel is in Browser or Application
This would be perfect, but I can't get it to work in 97 or 2003.
If I take out on error resume next, it always errors out. Either in a browser or application. Is there a reference I am missing?' "Jim Rech" wrote: This is a routine posted by Ture Magnusson that may may give you some ideas: Sub CheckIfInInternetExplorer() Dim x As Object 'Try to get container object On Error Resume Next Set x = ActiveWorkbook.Container On Error GoTo 0 'Show result depending on container's typename Select Case TypeName(x) 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 -- Jim Rech Excel MVP "Ken Valenti" <Ken wrote in message ... |I have a website with a hyperlink to an Excel spreadsheet. Some computers | are setup so that Excel opens in a browser, others open in the Excel | application. I need to know if Excel is in a browser or not - since most of | my macros don't work in a browser. | | Is there code to know if this? It has to work with Excel 97 through 2003. | I'm thinking if there is something that errors out when in a browser, I could | catch that error and know that way. | | Any insight is appreciated. |
All times are GMT +1. The time now is 08:26 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com