LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 37
Default urgent help with lock excel macros!!!

Hi to everyone,
I was looking for a way to make Excel like viewer. Surfing in the news
group I found this macro.
It works to lock Excel but now I can't unlock Excel back!!

Could someone help me?
I post it just below and hear is the link were I found it:
http://groups.google.com/group/micro...lnk=st&q=excel

Public Sub LockdownExcel()
Dim objTemp As Object
Dim cbBar As CommandBar
Dim ctrl As CommandBarControl
Dim cbarCount As Integer
Dim ctrlCount As Integer

'disable keys and change settings
With Application
.ScreenUpdating = False
.DisplayAlerts = False
.Visible = False
.OnKey "^X", ""
.OnKey "^x", ""
.OnKey "^C", ""
.OnKey "^c", ""
.OnKey "^V", ""
.OnKey "^v", ""
.OnKey "^9", "ThisWorkbook.UnlockExcel"
.CutCopyMode = False
.DisplayStatusBar = False
.DisplayFormulaBar = False
.IgnoreRemoteRequests = True
.ActiveWindow.DisplayHeadings = False
.ActiveWindow.DisplayWorkbookTabs = False
.WindowState = xlMaximized
.ActiveWindow.WindowState = xlMaximized
.EnableEvents = False

.CommandBars.DisableAskAQuestionDropdown = True
.CommandBars.DisableCustomize = True

cbarCount = 0
On Error Resume Next
For Each cbBar In .CommandBars
If cbBar.Visible Then
cbarCount = cbarCount + 1
Worksheets("CommandBars").Cells(cbarCount, 1).Value =
cbBar.Name
cbBar.Visible = False
cbBar.Enabled = False
End If
Next cbBar

ctrlCount = 0
For Each ctrl In .CommandBars.ActiveMenuBar.Controls
If ctrl.Visible Then
ctrlCount = ctrlCount + 1
Worksheets("CommandBars").Cells(ctrlCount, 3).Value =
ctrl.Index
ctrl.Visible = False
ctrl.Enabled = False
End If
Next ctrl
On Error GoTo 0

.DisplayAlerts = True
.ScreenUpdating = True
.Visible = True
.EnableEvents = True
End With
excelLocked = True
End Sub

Public Sub UnlockExcel()
Dim cbBar As CommandBar
Dim cbarCount As Integer, cbarTotal As Integer
Dim ctrl As Control
Dim ctrlCount As Integer, ctrlTotal As Integer

'restore command bars
With Worksheets("CommandBars")
cbarTotal = CInt(.Cells(1, 2).Value)
ctrlTotal = CInt(.Cells(1, 4).Value)

On Error Resume Next

For ctrlCount = 1 To ctrlTotal

Application.CommandBars.ActiveMenuBar.Controls(.Ce lls(ctrlCount,
3).Value).Enabled = True

Application.CommandBars.ActiveMenuBar.Controls(.Ce lls(ctrlCount,
3).Value).Visible = True
.Cells(ctrlCount, 3).Value = ""
Next ctrlCount

For cbarCount = 1 To cbarTotal
Application.CommandBars(.Cells(cbarCount,
1).Value).Enabled = True
Application.CommandBars(.Cells(cbarCount,
1).Value).Visible = True
.Cells(cbarCount, 1).Value = ""
Next cbarCount

On Error GoTo 0
End With

'restore shortcut keys and other settings
With Application
.CommandBars.DisableAskAQuestionDropdown = False
.CommandBars.DisableCustomize = False
.OnKey "^X"
.OnKey "^x"
.OnKey "^C"
.OnKey "^c"
.OnKey "^V"
.OnKey "^v"
.OnKey "^9", "ThisWorkbook.LockdownExcel"
.CutCopyMode = xlCopy
.DisplayStatusBar = True
.DisplayFormulaBar = True
.IgnoreRemoteRequests = False
.ActiveWindow.DisplayHeadings = True
.ActiveWindow.DisplayWorkbookTabs = True
End With
excelLocked = False
End Sub

Many thanks to everyone!
Bye,
Stefano.
 
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
How can you lock macros SAM SEBAIHI Excel Discussion (Misc queries) 2 December 1st 06 04:15 AM
Training: More on how to use macros in Excel: Recording Macros ToriT Excel Worksheet Functions 2 February 10th 06 07:05 PM
How can I lock worksheets while macros can still enter into them? enginguven Excel Discussion (Misc queries) 3 January 12th 06 12:56 AM
How can I lock worksheets while still allowing macros to operate? enginguven Excel Discussion (Misc queries) 2 January 9th 06 10:06 PM
How can I lock worksheets while still allowing macros to operate? enginguven Excel Discussion (Misc queries) 1 January 9th 06 09:47 PM


All times are GMT +1. The time now is 10:22 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"