PDA

View Full Version : Solved: Change and restore fill-style



zxmon21
03-04-2012, 03:26 PM
Hi,
I am trying to mark a shape (by changing fill to red), then ask the user if this is the shape we are looking for, and then restore the original fill style.

Any ideas how to save and restore the fill style of a shape? It could be a complex fill like gradients etc, so I'd rather not just save the BackColor.RGB.

What I'm doing now throws an error "Object required"

Any help is much appreciated :)


'save runshp.background color in dummy variable
OldBg = runshp.Fill '<-- This line throws an error
runshp.Fill.BackColor.RGB = RGB(255, 0, 0)

'throw a messagebox asking if this is the right shape selected
If MsgBox("I think I detected a chapter title, but am not quite sure. Is it the shape I labelled in red?", vbYesNo) = 6 Then
runshp.Name = "ChapterTitle"
'this is it
End If
runshp.Fill = OldBg '<-- I bet this will also throw an error

John Wilson
03-05-2012, 01:20 AM
Try this:

Sub chex()
Dim selShp As Shape
If ActiveWindow.Selection.Type <> ppSelectionShapes Then Exit Sub
Set selShp = ActiveWindow.Selection.ShapeRange(1)
selShp.PickUp
selShp.Fill.Solid
selShp.Fill.ForeColor.RGB = vbRed
If MsgBox("I think I detected a chapter title, but am not quite sure. Is it the shape I labelled in red?", vbYesNo) = 6 Then selShp.Name = "ChapterTitle"
selShp.Apply
End Sub
You will need to change the selection code if this is not what you need but the principle should be the same. Microsoft use Fore and Back color in a confusing way but Forecolor is correct here (and usually unless there are two colors involved like a pattern / gradient)

zxmon21
03-05-2012, 05:22 AM
Hi John,
thanks for the quick reply! Your suggestion does precisely what I had hoped for.