Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Running a macro to edit one line in existing VBA

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.....

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Running a macro to edit one line in existing VBA

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


wrote in message
ups.com...
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.....



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Running a macro to edit one line in existing VBA

Thanks very much, exactly what I was looking for.

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
Running a macro from a command line Kelly Excel Programming 4 November 30th 04 08:17 PM
Running a macro from the command line Czech Excel Programming 1 October 28th 04 09:51 PM
Macro to edit existing formulas LowKey Excel Programming 1 October 16th 04 09:16 PM
Excel open an existing MS Query in edit mode via macro attached to a button. systems analyst Excel Programming 1 October 3rd 03 12:08 PM
running macro while in the edit mode Bob[_23_] Excel Programming 2 July 24th 03 01:38 AM


All times are GMT +1. The time now is 01:55 PM.

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"