Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 44
Default lock excel worksheet when loosing focus

Hello,

I would like to lock my excel worksheet as soon as I loose focus. An exemple
: Let's I'm puting values into my sheet and then I decide to write a word
document. Once I clicked on "Start" (Programs-etc...), I want my excel to
lock itself and then if I go back to my excel sheet I will be asked for a
password.

Is there a lost focus on worksheet method in excel vba ?

Thanks in advance

Nader

PS : all this is to avoid to put in value by mistake in my excel sheet



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default lock excel worksheet when loosing focus

Excel cannot you this directly as there is no Application_LostFocus event.
You will have use some API calls within a Timer to see if Excel is the
ForeGround window.

NickHK

"Nader" wrote in message
...
Hello,

I would like to lock my excel worksheet as soon as I loose focus. An

exemple
: Let's I'm puting values into my sheet and then I decide to write a word
document. Once I clicked on "Start" (Programs-etc...), I want my excel to
lock itself and then if I go back to my excel sheet I will be asked for a
password.

Is there a lost focus on worksheet method in excel vba ?

Thanks in advance

Nader

PS : all this is to avoid to put in value by mistake in my excel sheet





  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default lock excel worksheet when loosing focus

Nader,

Not what you originally asked for but may be an acceptable 'simple'
solution for you...

PS : all this is to avoid to put in value by mistake in my excel sheet


Try putting the following procedure in your worksheet code module. It
will mean hitting Return twice for every legitimate entry but may be an
acceptable overhead to avoid an accidental entry...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim Response As Variant
Dim msg As String
Dim Title As String

msg = Target.Range("A1").Address & " = '" &
Target.Range("A1").Value & "'"
msg = msg & vbCrLf & vbCrLf
msg = msg & "Accept entry?"

Title = "Confirm Entry"

Response = MsgBox(msg, vbYesNo + vbQuestion, Title)

If Response = vbNo Then
With Application
.EnableEvents = False
.Undo
.EnableEvents = True
End With
End If
End Sub

Kind regards,
NickH



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 60
Default lock excel worksheet when loosing focus

Oops, beware the wrap-around:

Target.Range("A1").Value & "'"

belongs on the end of the preceding line.

Nick H

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
Loosing data in shared worksheet. NealMed Excel Worksheet Functions 0 June 12th 07 12:56 AM
how do I lock only a few cells in Excel within a worksheet? Locking cells in Excel Excel Worksheet Functions 2 August 25th 06 02:46 AM
lock rows and columns on a web Excel worksheet. User Friendly Excel Discussion (Misc queries) 0 August 17th 06 01:29 PM
Excel crashes everytime I send focus from control to worksheet Daves_Solutions[_2_] Excel Programming 2 June 11th 06 05:02 PM
How to Lock the selected cells in Excel worksheet Siva New Users to Excel 1 May 8th 06 11:52 AM


All times are GMT +1. The time now is 04:11 PM.

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

About Us

"It's about Microsoft Excel"