Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / January 2006

Tip: Looking for answers? Try searching our database.

Running a macro to edit one line in existing VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
jbeard@barrick.com.au - 25 Jan 2006 03:45 GMT
CAN ANYONE HELP????

Please????

I am trying to run a simple macro in a protected workbook.

The workbook is protected adn so too are the worksheets, so the first
part of the macro is to remove the protection throughout - easy. The
second part is that I have the following code on several of the
worksheets which simply maintains the cell formatting when protected
(as some cells are allowed access for editting):

Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
End Sub

ActiveWorkbook.Unprotect Password:="techserv"

   Me.Unprotect Password:="techserv"

   With Application
       .EnableEvents = False
       .ScreenUpdating = False
   End With

  Worksheets("Formats").Range("q10:au131").Copy
   Me.Range("q10:au131").PasteSpecial Paste:=xlPasteFormats
   Target.Select

   With Application
       .EnableEvents = True
       .ScreenUpdating = True
   End With

   Me.Protect Password:="techserv"
ActiveWorkbook.Protect Password:="techserv"

End Sub

As this is effectively running all the time as soon as I (the owner of
the workbook) want to edit it I have to manually go to the VBA window
and type in End Sub after Private Sub to stop it while I work on it.

What code do I need to add to the first macro (which removes the
protection) so that it will automatically do this for me????

Any help would be much appreciated.....
Norman Jones - 25 Jan 2006 03:54 GMT
Hi J,

Application.EnableEvents = False

   'Your code

Application.EnableEvents = True

You could alternatively re-write the code to avoid selections, which are
usually unnecessary and inefficient and, in this case, fire your selection
change event code.

---
Regards,
Norman

> CAN ANYONE HELP????
>
[quoted text clipped - 43 lines]
>
> Any help would be much appreciated.....
jbeard@barrick.com.au - 25 Jan 2006 07:45 GMT
Thanks very much, exactly what I was looking for.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.