Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default closing the active workbook


Hi

I am trying to write some code that when the workbook is opened, it
prompts the user for a password and if an invalid password is entered
it closes the workbook.

This seems pretty simple. Putting the below snippet into the open
event ...

pass_dpanel.Show
If (pass_dpanel.TextBox1.Value < "correct") Then
' not valid password
MsgBox ("invalid password")
ActiveWorkbook.Close
End If

Which works ok until I copy the workbook onto our web server. This
time when an incrrect password is entered a duplicate file is opened
myworkbook[1].xls and if an incorrecte passwrod is entered for a
seccond time I get an "Invalid operation" error.

Any ideas ?


--
jmoffat
------------------------------------------------------------------------
jmoffat's Profile: http://www.excelforum.com/member.php...fo&userid=1151
View this thread: http://www.excelforum.com/showthread...hreadid=535477

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 477
Default closing the active workbook

Try

MsgBox ("invalid password")
ThisWorkbook.Close <<<<< Note change..
End If

HTH,

"jmoffat" wrote:


Hi

I am trying to write some code that when the workbook is opened, it
prompts the user for a password and if an invalid password is entered
it closes the workbook.

This seems pretty simple. Putting the below snippet into the open
event ...

pass_dpanel.Show
If (pass_dpanel.TextBox1.Value < "correct") Then
' not valid password
MsgBox ("invalid password")
ActiveWorkbook.Close
End If

Which works ok until I copy the workbook onto our web server. This
time when an incrrect password is entered a duplicate file is opened
myworkbook[1].xls and if an incorrecte passwrod is entered for a
seccond time I get an "Invalid operation" error.

Any ideas ?


--
jmoffat
------------------------------------------------------------------------
jmoffat's Profile: http://www.excelforum.com/member.php...fo&userid=1151
View this thread: http://www.excelforum.com/showthread...hreadid=535477


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default closing the active workbook


no it didn't work

I get the same error




--
jmoffat
------------------------------------------------------------------------
jmoffat's Profile: http://www.excelforum.com/member.php...fo&userid=1151
View this thread: http://www.excelforum.com/showthread...hreadid=535477

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default closing the active workbook

I tried it on a web server and got an error created by a reference to
another project (Rob Bovey's code cleaner infact). Not a problem on my
own machine. Maybe you could try removing any references that arn't
really required?? Bit of a long shot.

Paul

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default closing the active workbook


there are no such references the code is pretty much as written

I have tried alternateive fix such as:

Private Sub Workbook_Open()
'
Call get_pass
If (Not pass_ok) Then
bname = ThisWorkbook.Name
Windows(bname).Visible = False
End If
'

But this didnt work either - once I put it onto the web server and ope
it via my browser, the workbook remains unhidden. Seems to be a proble
specific to the web

--
jmoffa
-----------------------------------------------------------------------
jmoffat's Profile: http://www.excelforum.com/member.php...nfo&userid=115
View this thread: http://www.excelforum.com/showthread.php?threadid=53547



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default closing the active workbook

Hi
I would guess so. It's an interesting issue and it would be nice to see
a solution! There must be a lot of excel files accessed from web
servers.

Paul

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default closing the active workbook


after much experimentation and in case anyone wants to know ...

It would appear that if you download excel from a web server via a
simple URL link then, when using the _open event or auto_open
subroutine, at least one workbook MUST remain open after the download.
Otherwise the borowser [MS internet explorer] opens up a copy called
something like: workbook[1].xls

So to close the active workbook (for example if the an entered password
is incorrect) you must ...

sub auto_open
pass_dpanel.Show
bname=activeworkbook.name
If (pass_dpanel.TextBox1.Value < "correct") Then
' not valid password
MsgBox ("invalid password")
workbooks.add <-- must do this to keep a workbook
open !
Workbooks(bname).Close
End If


--
jmoffat
------------------------------------------------------------------------
jmoffat's Profile: http://www.excelforum.com/member.php...fo&userid=1151
View this thread: http://www.excelforum.com/showthread...hreadid=535477

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Closing Hidden Workbook when Active Workbook is Closed SusanK521 Excel Programming 5 September 24th 05 12:27 AM
Closing a workbook and printing a non-active page Sleeping Bear[_2_] Excel Programming 4 August 5th 05 01:47 PM
closing active windows without saving changes Tony Excel Programming 2 March 26th 05 10:24 PM
Need help for closing the active worksheet only under conditions Frank Petschke Excel Programming 1 March 2nd 04 09:46 AM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM


All times are GMT +1. The time now is 01:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"