Consulting

Results 1 to 3 of 3

Thread: Solved: Change and restore fill-style

  1. #1
    VBAX Regular
    Joined
    Feb 2012
    Posts
    7
    Location

    Solved: Change and restore fill-style

    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

    [vba]
    '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
    [/vba]

  2. #2
    VBAX Master
    Joined
    Feb 2007
    Posts
    2,094
    Location
    Try this:

    [vba]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[/vba]
    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)
    John Wilson
    Microsoft PowerPoint MVP
    Amazing Free PowerPoint Tutorials
    http://www.pptalchemy.co.uk/powerpoi...tutorials.html

  3. #3
    VBAX Regular
    Joined
    Feb 2012
    Posts
    7
    Location
    Hi John,
    thanks for the quick reply! Your suggestion does precisely what I had hoped for.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •