View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
SkylineGTR SkylineGTR is offline
external usenet poster
 
Posts: 20
Default Detecting if workbook running in IE or in Excel

Thanks to both Jim and jmoffat,

I realised that I did not share the knowledge I gained - apologies! Do
not know whether this is the best way of doing things, but it works!

1) Create a new module called Module1. Put the following code in:
Public geContainerType As ContainerTypes

Enum ContainerTypes
RunningInExcel
RunningInIE
RunningInUnknownApp
End Enum

Public Sub initiateContainerTest()
Call Application.OnTime(Now + TimeSerial(0, 0, 7),
"CheckContainer")
End Sub


In Activate (*not* workbook_open), called initiateContainerText()

In Module1, add:


Public Sub CheckContainer()
Select Case ExcelOrIE
Case RunningInExcel
MsgBox "Running in Excel"
Case RunningInIE, RunningInUnknownApp
MsgBox "Running in IE"
End Select
End Sub

Public Function ExcelOrIE() As ContainerTypes
Dim lsContainerName As String

On Error GoTo IsExcel
lsContainerName = ThisWorkbook.Container.Name

If lsContainerName = "Microsoft Internet Explorer" Then
geContainerType = RunningInIE
Else
geContainerType = RunningInUnknownApp
End If

ExcelOrIE = geContainerType
Exit Function
IsExcel:
ExcelOrIE = RunningInExcel
End Function

If you do not put the delay in OnTime, then it seems to think it is
running in Excel, when in actual fact it is running in IE - go figure -
any idea. All I know is put the initiateContainerText in
workbook.activate and it works -reliably

Cheers.