Reputation: 49
Trying to write a code that search a shape color and then position it into somewhere.
Example:
If shape.Fill.ForeColor.RGB = RGB(210, 210, 210) Then
With shape
.Width = 700
.Height = 20
.Top = 80
.Left = 30
.Name = "TitleTextBox"
.Fill.Visible = msoFalse
.Fill.Transparency = 1.0 '(somehow when I type 1.0 it will become 1#, not sure why on this also)
End With
End if
How I use my code:
I using this code to add a fill color Grey = RGB(210,210,210) to certain shapes then clear the color and reposition the shape to where I wanted
However, when I run this code again, the shape that has added the Grey color will get reposition again, even though it doesn't have any fill to it.
Somehow, I felt the shape has remembered the color apply to them, which isn't what I wanted.
Appreciate if any one can provide me some insight on how I can overcome this problem.
Thanks
Upvotes: 3
Views: 7389
Reputation: 43585
Try like this:
Option Explicit
Public Sub TestMe()
Dim sh As Shape
Dim sld As Slide
Set sld = Application.ActiveWindow.View.Slide
For Each sh In sld.Shapes
If sh.Fill.ForeColor.RGB = RGB(210, 210, 210) Then
With sh
.Fill.ForeColor.RGB = RGB(0, 0, 0)
.Width = 700
.Height = 20
.Top = 80
.Left = 30
.Name = "TitleTextBox"
.Fill.Visible = msoFalse
.Fill.Transparency = 1#
End With
End If
Next sh
End Sub
Once you find the grey shape, make sure that you change its color to RGB(0,0,0)
. Thus, it will not be grey any more and will not be taken into account, if you run the code again. I have done it with this line:
.Fill.ForeColor.RGB = RGB(0, 0, 0)
Upvotes: 2