Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Trying to loop through all shapes on multiple worksheets and change color

Hi - I have a workbook with multiple sheets - each having a few shapes
on it. I want to change the color of the fill and line for each one.
My code works ok if I run it on just one sheet, but if I try and run it
on one sheet right after the other (with a subroutine calling this sub
twice), it gives me the "Object doesn't support the property or method"
error. Sometimes this even happens if I run the macro twice in a row
manually, sometimes it doesn't. I am seriously at my wits end....can
someone please help?

Thanks!

Here is the code I am bombing out
on...."Selection.ShapeRange.Fill.ForeColor.SchemeC olor = 16" (or
whichever case it is on)


For Each sh In myDocument.Shapes
sh.Select
If sh.Type = 2 Then
Select Case colorscheme

Case "OcOl"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 16
Selection.ShapeRange.Line.ForeColor.SchemeColor = 16
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With

Case "BoTe"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 34
Selection.ShapeRange.Line.ForeColor.SchemeColor = 34
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case "EaTe"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 34
Selection.ShapeRange.Line.ForeColor.SchemeColor = 34
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case "BoEa"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 35
Selection.ShapeRange.Line.ForeColor.SchemeColor = 35
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case Else
'Olive-Ocean is default
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 1
Selection.ShapeRange.Line.ForeColor.SchemeColor = 1
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With

End Select


End If
Next

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Trying to loop through all shapes on multiple worksheets and change color

Looks like you are trying to format all callouts on the assumption they
contain text.

See this question from earlier today
Subject Font.Color - syntax error ?

In passing, it also looks like you change these throughout the entire
workbook according to your own defined colour scheme. Instead of changing
all those formats you could customize a palette colour.

Eg format everything with (say) colorindex 31 or 31+7 = schemecolor 38
(bottom left in the dropdown palette)

first from the intermediate window (ctrl-g)
?activeworkbook.Colors(16-7)
16711935
?activeworkbook.Colors(35-7)
16776960
?activeworkbook.Colors(34-7)
65535
?vbwhite
16777215

Dim newcolor as long

Select case colorscheme
case "OcOl": newcolor = 16711935
case "BoTe": newcolor = 16776960
Case "EaTe":
Case Else
'Olive-Ocean is default
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 1


End select

Activeworkbook.colors(31) = newcolor

But I don't understand how 'Olive-Ocean goes to SchemeColor = 1, for me
it's vbWhite

In addition, you could set the default colour for all new shapes to be
colorindex 31 (shemecolor38), then you don't need to worry about running a
macro unless you change your colorsheme.

Just a thought

Regards,
Peter


wrote in message
oups.com...
Hi - I have a workbook with multiple sheets - each having a few shapes
on it. I want to change the color of the fill and line for each one.
My code works ok if I run it on just one sheet, but if I try and run it
on one sheet right after the other (with a subroutine calling this sub
twice), it gives me the "Object doesn't support the property or method"
error. Sometimes this even happens if I run the macro twice in a row
manually, sometimes it doesn't. I am seriously at my wits end....can
someone please help?

Thanks!

Here is the code I am bombing out
on...."Selection.ShapeRange.Fill.ForeColor.SchemeC olor = 16" (or
whichever case it is on)


For Each sh In myDocument.Shapes
sh.Select
If sh.Type = 2 Then
Select Case colorscheme

Case "OcOl"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 16
Selection.ShapeRange.Line.ForeColor.SchemeColor = 16
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With

Case "BoTe"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 34
Selection.ShapeRange.Line.ForeColor.SchemeColor = 34
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case "EaTe"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 34
Selection.ShapeRange.Line.ForeColor.SchemeColor = 34
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case "BoEa"
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 35
Selection.ShapeRange.Line.ForeColor.SchemeColor = 35
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With
Case Else
'Olive-Ocean is default
Selection.ShapeRange.Fill.ForeColor.SchemeColor = 1
Selection.ShapeRange.Line.ForeColor.SchemeColor = 1
With Selection.Characters.Font
.Name = "Arial"
.FontStyle = "Regular"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = fontcolor
End With

End Select


End If
Next



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
Change multiple worksheets at one time to print in color Sundance Excel Discussion (Misc queries) 1 January 5th 10 10:34 PM
How do i change the size of multiple shapes at the same time? Amber Excel Discussion (Misc queries) 0 September 25th 08 09:14 PM
Loop to change cell color based on found value? gaba Excel Programming 3 November 3rd 04 02:33 PM
Summing loop for multiple worksheets Brian Easton Excel Programming 1 September 25th 04 12:43 AM
PROB: Grouping Shapes With An Array Loop Boicie Excel Programming 2 January 14th 04 08:21 PM


All times are GMT +1. The time now is 03:42 AM.

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"