Change Excel system messages

Folks,
When certain cells in a worksheet are protected Excel gives you a message. Is there anyway to create your own messages and not use Excel's? I know in Access you can capture the error code and generate your own message so I was wondering if you could not do the same in Excel.
Frank FreeseAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rspahitzCommented:
I'm not sure how to do this within Excel directly, but if you're talking about macros that show the problem, try something like this:

Sub x()
    On Error GoTo Error_Trap
    
' your code goes here, which will try to access a locked/protected cell
    'Range("D5").Value = 3

NormalExit:    
    Exit Sub

    
Error_Trap:
    If Err.Number = 1004 Then
        MsgBox "The sheet is protected.  Contact us to fix this problem.", vbOKOnly Or vbExclamation
    Else
        MsgBox Err.Description
    End If
    Resume NormalExit
End Sub

Open in new window


The idea is to set up error trapping and trap that message (which seems to be 1004, although you may have to check err.Number if yours is different) then show your custom message.
Make sure to Resume back to the main routine and make sure to have an Exit Sub to exit before the error trap.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Frank FreeseAuthor Commented:
Thanks - looks like the same thing in Access - I'll try it this afternoon
0
gowflowCommented:
Well basically you can go along these lines and add the routines
NotifyUserGeneral
NotifyUserCell

that are saved in a module depending on how you want to notify the user. If on a cell action basis then NotifyUserCell or if just on a sheet activate basis then NotifyUserGeneral

The way this workbook is set is that Sheet1 is protected and you get notified on both actions all others sheets are not protected.

If you want to simply protect sheet2 then add this code for sheet2

Private Sub Worksheet_Activate()

    NotifyUserGeneral

End Sub

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    NotifyUserCell

End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    NotifyUserCell

End Sub

Open in new window


This solution was given by zorvek at this link
http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28037337.html
gowflow
ProtectUnprotectOwnMsg.xlsm
0
C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

gowflowCommented:
@rspahitz
Your code is simply error handling and will not react when sheet is protected.
gowflow
0
Frank FreeseAuthor Commented:
Thank you folks...I can see me incorporating both suggestions.
Good work - 50/50 spread
0
Frank FreeseAuthor Commented:
all good suggestions
appreciate all the experts very much
0
rspahitzCommented:
Glad that the information was useful.  It's always good practice to put error-trapping in any piece of code (*) that could potentially create an error (and in Excel, it's almost every piece of code.)

(*) subs called by error-handled methods may not need error-traps if you don't mind the error floating up, but then you typically lose access to the line or other information about where the error occurred.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.