PC Review


Reply
Thread Tools Rate Thread

Code seems to stop, but no error messages show up

 
 
=?Utf-8?B?QkVFSkFZ?=
Guest
Posts: n/a
 
      19th Oct 2006
The main part of the following code works great when I run it
from an icon my machine.
Now trying to add this code to an add-in to be distributed.
When I try F8, it does go into Call Green, but just loops and loops, without
turning any cells green.
When I run the Print Contracts from my custom menu, based on the worksheet
and workbook protection status, the code seems to skip the Call Green and End
sub.
Can anyone please check and advise what I am missing here?

Option Explicit
Sub PrintContract()
' PrintContract Macro
' Keyboard Shortcut: NONE

Application.ScreenUpdating = False

Worksheets("Contract").Select
ActiveSheet.Unprotect Password:="1234"

Cells.Select
Selection.Interior.ColorIndex = -4142

ActiveSheet.Protect Password:="1234"
Worksheets("Contract").PrintOut Copies:=1, Collate:=True

Call Green

Application.ScreenUpdating = True
End Sub

Sub Green()
ActiveWorkbook.Unprotect Password:="4321"
ActiveSheet.Unprotect Password:="1234"
'===============================================
Dim CELL As Range, tempR As Range, rangeToCheck As Range
Cells.Select
Cells.Interior.ColorIndex = -4142
For Each CELL In Intersect(Selection, ActiveSheet.UsedRange)
If Not CELL.Locked Then
If tempR Is Nothing Then
Set tempR = CELL
Else
Set tempR = Union(tempR, CELL)
End If
End If

Next CELL
If tempR Is Nothing Then
MsgBox "There are no Unlocked cells " & _
"in the selected range."
End
End If

'Select qualifying cells
'TempR.Select
tempR.Interior.ColorIndex = 4 'GREEN
' =================================================
ActiveSheet.Protect Password:="1234"
ActiveWorkbook.Protect Password:="4321"

End Sub

 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmltIFRob21saW5zb24=?=
Guest
Posts: n/a
 
      19th Oct 2006
When you put the code into the addin you need to be very explicit in your
references. Make sure theat you reference the activesheet. I also cleaned up
the code just a bit... I removed the selects and I removed the stand alone
End (A stand alone end will clear all global variables). One thing to note is
taht this code could be a problem if the used range gets messed up. That can
be fixed latter if you wish...

Sub Green()
Dim CELL As Range, tempR As Range, rangeToCheck As Range

With ActiveSheet
ActiveWorkbook.Unprotect Password:="4321"
.Unprotect Password:="1234"
'===============================================
.Cells.Interior.ColorIndex = -4142
For Each CELL In .UsedRange
If Not CELL.Locked Then
If tempR Is Nothing Then
Set tempR = CELL
Else
Set tempR = Union(tempR, CELL)
End If
End If
Next CELL

If tempR Is Nothing Then
MsgBox "There are no Unlocked cells " & _
"in the selected range."
Else
tempR.Interior.ColorIndex = 4
End If

' =================================================
.Protect Password:="1234"
ActiveWorkbook.Protect Password:="4321"
End With
End Sub
--
HTH...

Jim Thomlinson


"BEEJAY" wrote:

> The main part of the following code works great when I run it
> from an icon my machine.
> Now trying to add this code to an add-in to be distributed.
> When I try F8, it does go into Call Green, but just loops and loops, without
> turning any cells green.
> When I run the Print Contracts from my custom menu, based on the worksheet
> and workbook protection status, the code seems to skip the Call Green and End
> sub.
> Can anyone please check and advise what I am missing here?
>
> Option Explicit
> Sub PrintContract()
> ' PrintContract Macro
> ' Keyboard Shortcut: NONE
>
> Application.ScreenUpdating = False
>
> Worksheets("Contract").Select
> ActiveSheet.Unprotect Password:="1234"
>
> Cells.Select
> Selection.Interior.ColorIndex = -4142
>
> ActiveSheet.Protect Password:="1234"
> Worksheets("Contract").PrintOut Copies:=1, Collate:=True
>
> Call Green
>
> Application.ScreenUpdating = True
> End Sub
>
> Sub Green()
> ActiveWorkbook.Unprotect Password:="4321"
> ActiveSheet.Unprotect Password:="1234"
> '===============================================
> Dim CELL As Range, tempR As Range, rangeToCheck As Range
> Cells.Select
> Cells.Interior.ColorIndex = -4142
> For Each CELL In Intersect(Selection, ActiveSheet.UsedRange)
> If Not CELL.Locked Then
> If tempR Is Nothing Then
> Set tempR = CELL
> Else
> Set tempR = Union(tempR, CELL)
> End If
> End If
>
> Next CELL
> If tempR Is Nothing Then
> MsgBox "There are no Unlocked cells " & _
> "in the selected range."
> End
> End If
>
> 'Select qualifying cells
> 'TempR.Select
> tempR.Interior.ColorIndex = 4 'GREEN
> ' =================================================
> ActiveSheet.Protect Password:="1234"
> ActiveWorkbook.Protect Password:="4321"
>
> End Sub
>

 
Reply With Quote
 
=?Utf-8?B?QkVFSkFZ?=
Guest
Posts: n/a
 
      20th Oct 2006
Thanks Jim:

1: Could you please explain your last statement?
The sheets I use this code on are constantly getting rows inserted, deleted
and moved. When I have "enough" significant changes, I send this latest
version contract(s) to my salesmen. They do not have the capability of adding
or deleting rows - they can only work with the coloured cells - the rest are
locked and there is w/sheet and w/book protection in place.

2: ALSO: I regularily use the code ( I think I got it from 'Contextures')
to clean up (delete) the unused range.
The Question then, Is there other things happening with w/sheets that are
constantly being manipulated (add rows, delete rows, move rows), that one
should (consider) totally rebuilding the sheets from scratch, on a "regular"
basis?
FYI: I am almost done "cleaning up" all my code modules (copy to text,
make new module with new name, copy text into new module, etc.)

Jim, I thank you in advance for your consideration of the above items.


"Jim Thomlinson" wrote:

> When you put the code into the addin you need to be very explicit in your
> references. Make sure theat you reference the activesheet. I also cleaned up
> the code just a bit... I removed the selects and I removed the stand alone
> End (A stand alone end will clear all global variables). One thing to note is
> taht this code could be a problem if the used range gets messed up. That can
> be fixed latter if you wish...
>
> Sub Green()
> Dim CELL As Range, tempR As Range, rangeToCheck As Range
>
> With ActiveSheet
> ActiveWorkbook.Unprotect Password:="4321"
> .Unprotect Password:="1234"
> '===============================================
> .Cells.Interior.ColorIndex = -4142
> For Each CELL In .UsedRange
> If Not CELL.Locked Then
> If tempR Is Nothing Then
> Set tempR = CELL
> Else
> Set tempR = Union(tempR, CELL)
> End If
> End If
> Next CELL
>
> If tempR Is Nothing Then
> MsgBox "There are no Unlocked cells " & _
> "in the selected range."
> Else
> tempR.Interior.ColorIndex = 4
> End If
>
> ' =================================================
> .Protect Password:="1234"
> ActiveWorkbook.Protect Password:="4321"
> End With
> End Sub
> --
> HTH...
>
> Jim Thomlinson
>
>
> "BEEJAY" wrote:
>
> > The main part of the following code works great when I run it
> > from an icon my machine.
> > Now trying to add this code to an add-in to be distributed.
> > When I try F8, it does go into Call Green, but just loops and loops, without
> > turning any cells green.
> > When I run the Print Contracts from my custom menu, based on the worksheet
> > and workbook protection status, the code seems to skip the Call Green and End
> > sub.
> > Can anyone please check and advise what I am missing here?
> >
> > Option Explicit
> > Sub PrintContract()
> > ' PrintContract Macro
> > ' Keyboard Shortcut: NONE
> >
> > Application.ScreenUpdating = False
> >
> > Worksheets("Contract").Select
> > ActiveSheet.Unprotect Password:="1234"
> >
> > Cells.Select
> > Selection.Interior.ColorIndex = -4142
> >
> > ActiveSheet.Protect Password:="1234"
> > Worksheets("Contract").PrintOut Copies:=1, Collate:=True
> >
> > Call Green
> >
> > Application.ScreenUpdating = True
> > End Sub
> >
> > Sub Green()
> > ActiveWorkbook.Unprotect Password:="4321"
> > ActiveSheet.Unprotect Password:="1234"
> > '===============================================
> > Dim CELL As Range, tempR As Range, rangeToCheck As Range
> > Cells.Select
> > Cells.Interior.ColorIndex = -4142
> > For Each CELL In Intersect(Selection, ActiveSheet.UsedRange)
> > If Not CELL.Locked Then
> > If tempR Is Nothing Then
> > Set tempR = CELL
> > Else
> > Set tempR = Union(tempR, CELL)
> > End If
> > End If
> >
> > Next CELL
> > If tempR Is Nothing Then
> > MsgBox "There are no Unlocked cells " & _
> > "in the selected range."
> > End
> > End If
> >
> > 'Select qualifying cells
> > 'TempR.Select
> > tempR.Interior.ColorIndex = 4 'GREEN
> > ' =================================================
> > ActiveSheet.Protect Password:="1234"
> > ActiveWorkbook.Protect Password:="4321"
> >
> > End Sub
> >

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stop error messages Michael Windows XP Help 7 30th Jan 2008 04:03 AM
Stop Error Messages =?Utf-8?B?c25ha3lzbW9t?= Windows XP Accessibility 2 21st Oct 2004 09:12 PM
STOP error messages Windows XP Performance 0 9th May 2004 02:26 PM
How to stop "thread exited with error code 0" messages from appearing? Carl Rosenberger Microsoft C# .NET 0 27th Nov 2003 12:01 PM
XP Pro Stop Error Messages Gee Windows XP Basics 2 19th Oct 2003 01:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:23 AM.