ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test if spreadsheet id open in IE (https://www.excelbanter.com/excel-programming/327188-test-if-spreadsheet-id-open-ie.html)

Jan Kronsell[_4_]

Test if spreadsheet id open in IE
 
Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel or in
Excel showing in an Internet Explorer window?

Jan



keepITcool

Test if spreadsheet id open in IE
 
Jan,

I did a bit of puzzling, but following seems to work
in most cases. (When explorer is open, or when workbook is
open with "open with" Internet Explorer.

the structure of the windows, window parents and captions
is slightly different. However.. there's the IsInPlace property.

You must use the OnTime, as events are run first, before the window is
placed in the IEframe... so you have to build a delay..

Once the user has the window visible the delay is not needed.


'Thisworkbook..
Option Explicit

Dim bDone As Boolean

Private Sub Workbook_Activate()
If Not bDone Then
bDone = True
Call Application.OnTime(Now + TimeSerial(0, 0, 1), _
ThisWorkbook.Name & "!TimedMsg")
End If
End Sub

'Normal non private module
Option Explicit

Sub TimedMsg()
If ThisWorkbook.IsInPlace Then
MsgBox "Yep. I'm loaded in internet Explorer"
endif
End Sub


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jan Kronsell wrote :

Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel or
in Excel showing in an Internet Explorer window?

Jan


Peter T

Test if spreadsheet id open in IE
 
If ThisWorkbook.IsInPlace Then

I think this would confirm the file is not opened in Excel but as an object
in some other app, that might but not necessarily be IE ?

Regards,
Peter T

"keepITcool" wrote in message
.com...
Jan,

I did a bit of puzzling, but following seems to work
in most cases. (When explorer is open, or when workbook is
open with "open with" Internet Explorer.

the structure of the windows, window parents and captions
is slightly different. However.. there's the IsInPlace property.

You must use the OnTime, as events are run first, before the window is
placed in the IEframe... so you have to build a delay..

Once the user has the window visible the delay is not needed.


'Thisworkbook..
Option Explicit

Dim bDone As Boolean

Private Sub Workbook_Activate()
If Not bDone Then
bDone = True
Call Application.OnTime(Now + TimeSerial(0, 0, 1), _
ThisWorkbook.Name & "!TimedMsg")
End If
End Sub

'Normal non private module
Option Explicit

Sub TimedMsg()
If ThisWorkbook.IsInPlace Then
MsgBox "Yep. I'm loaded in internet Explorer"
endif
End Sub


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jan Kronsell wrote :

Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel or
in Excel showing in an Internet Explorer window?

Jan




Jan Kronsell[_4_]

Test if spreadsheet id open in IE
 
Hi

I give a shot, then get back to you.

Jan


"keepITcool" wrote in message
.com...
Jan,

I did a bit of puzzling, but following seems to work
in most cases. (When explorer is open, or when workbook is
open with "open with" Internet Explorer.

the structure of the windows, window parents and captions
is slightly different. However.. there's the IsInPlace property.

You must use the OnTime, as events are run first, before the window is
placed in the IEframe... so you have to build a delay..

Once the user has the window visible the delay is not needed.


'Thisworkbook..
Option Explicit

Dim bDone As Boolean

Private Sub Workbook_Activate()
If Not bDone Then
bDone = True
Call Application.OnTime(Now + TimeSerial(0, 0, 1), _
ThisWorkbook.Name & "!TimedMsg")
End If
End Sub

'Normal non private module
Option Explicit

Sub TimedMsg()
If ThisWorkbook.IsInPlace Then
MsgBox "Yep. I'm loaded in internet Explorer"
endif
End Sub


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


Jan Kronsell wrote :

Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel or
in Excel showing in an Internet Explorer window?

Jan




K Dales[_2_]

Test if spreadsheet id open in IE
 
A better method is to use the Container property of the workbook. This gives
and Object reference to the containing object IF the book is open as an
embedded object (e.g. in IE). It fails (errors) if Excel is open as a
standalone app, so that needs to be determined with some error handling.

Public Function ExcelOrIE() As String
Dim CName as String

On Error Goto MustBeExcel
CName = ThisWorkbook.Container.Name

If CName = "Microsoft Internet Explorer" Then CName = "IE" Else CName =
"Something Else"

ExcelOrIE = CName
Exit Function

MustBeExcel:
ExcelorIE = "Excel"

End Function

"Jan Kronsell" wrote:

Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel or in
Excel showing in an Internet Explorer window?

Jan




keepITcool

Test if spreadsheet id open in IE
 
Thnx.

I agree container gives more info then IsInPlace.
thnx for the tip.

See my original post for delaying any event macro's until loading is
complete before calling on the container.


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


K Dales wrote :

A better method is to use the Container property of the workbook.
This gives and Object reference to the containing object IF the book
is open as an embedded object (e.g. in IE). It fails (errors) if
Excel is open as a standalone app, so that needs to be determined
with some error handling.

Public Function ExcelOrIE() As String
Dim CName as String

On Error Goto MustBeExcel
CName = ThisWorkbook.Container.Name

If CName = "Microsoft Internet Explorer" Then CName = "IE" Else CName
= "Something Else"

ExcelOrIE = CName
Exit Function

MustBeExcel:
ExcelorIE = "Excel"

End Function

"Jan Kronsell" wrote:

Hi NG!

Is there a way to test if a spreadsheet is opened in native Excel
or in Excel showing in an Internet Explorer window?

Jan





All times are GMT +1. The time now is 02:09 PM.

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