Determine if Excel is running in a browser window

  • Thread starter Thread starter John Michl
  • Start date Start date
J

John Michl

Is there a way to determine if the user is running Excel in a browser
window or in an instance of Excel?

I have a calculator model that is posted on our intranet. The
instructions indicate that people are supposed right-click on the link
and save it to their computer then open it in Excel. Inevitable,
people double-click then start using the tool in a browser window
instead. Much of the VBA code doesn't work properly.

I'll like to change the workbook_open code to
1) Determine if in browser mode and if so, then
2) Issue a warning.

Thanks.

- John
 
I don't have any experience with it, but to a similar question, KeepItCool
replied:

1 From: keepITcool - view profile
Date: Mon, Jun 13 2005 10:37 am
Email: "keepITcool" <[email protected]>
Groups: microsoft.public.excel.programming
Not yet ratedRating:
show options
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author


look at the workbooks' container property

but be carefull you cannot do it in any open event
as the container is only available when the book is
fully loaded.


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


stockbuildingsupply wrote :



- Hide quoted text -
- Show quoted text -
i have a web application that streams an excel workbook to the
client. i want to prevent the user from saving the workbook locally.
the user should only be able to work with the workbook through the
web browser. is there a way to tell if excel is being run in a web
browser?


Reply

2 From: keepITcool - view profile
Date: Mon, Jun 13 2005 7:46 pm
Email: "keepITcool" <[email protected]>
Groups: microsoft.public.excel.programming
Not yet ratedRating:
show options
Reply | Reply to Author | Forward | Print | Individual Message | Show
original | Report Abuse | Find messages by this author


it cannot be placed in the activation event directly.
you'll need to delay it until activation has completed.


In the workbook_activate event include an application.ontime
to call the "containertest" with a 1 second delay.
 
Here's my solution.

In ThisWorkbook:

Dim bDone As Boolean

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


In Module1:

Sub TimedMsg()

On Error GoTo NativeExcel

CName = ThisWorkbook.Container.Name ' will error if no container
(Native Excel = no container)
MsgBox "Warning! You are running in a browser window."
Exit Sub

NativeExcel:
MsgBox "You're in Excel."

End Sub
 
John,
Thank you for posting your solution. While I don't have a current need
for it, it is DEFINITELY going into my library for future use.!!!
Sincerely,
Gary Brown
(e-mail address removed)
 
That confirms if the workbook is 'contained' in what may or may not be a
browser. If that's all you need could return IsInPlace without need to
handle the possible error. Though would still need to wait until fully
loaded.

If necessary adapt along the lines of K-Dales example -
http://tinyurl.com/yhbg4v

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top