I can cycle it on/off but can't figure out how to "reset" it. Once a color shape is deleted the doc palette still shows the color until you click thru and hit reset.
Sub RefreshDocPalette() ActiveDocument.Palette.Close
ActiveDocument.Palette.Open
End Sub
P.s. why after hitting "reset palette" does it add a black swatch even though there's no black used in the doc.
For i = ActiveDocument.Palette.Colors.Count To 1 Step -1 ActiveDocument.Palette.RemoveColor (i)Next i
that removes all colors. I just want to remove the color that's not used anywhere.
this one was offered to try but throws an error and still isn't right (see next post)
Sub RefreshDocPalette2()Dim c As Color, sr As New ShapeRange, srAllShapes As ShapeRange, s As Shape Set srAllShapes = ActivePage.Shapes.All For Each c In ActiveDocument.Palette.Colors For Each s In srAllShapes If s.Fill.Type = cdrUniformFill Then If c.IsSame(s.Fill.UniformColor) Then sr.Add s End If Next s If sr.Count > 0 Then srAllShapes.RemoveRange sr: sr.RemoveAll Else With ActiveDocument.Palette .RemoveColor .GetIndexOfColor(c) End With End If Next cEnd Sub
Try this:
Sub ResetPalette(ByRef iDoc As Document)Dim CurColNo As Integer, CurPg As Page, CurSh As Shape, CurSR As ShapeRange, DoIt As BooleanFor CurColNo = iDoc.Palette.Colors.Count To 1 Step -1 DoIt = True For Each CurPg In iDoc.Pages Set CurSR = CurPg.Shapes.All If CurSR.Shapes.Count > 0 Then For Each CurSh In CurSR.Shapes If CurSh.Fill.Type = cdrUniformFill Then If CurSh.Fill.UniformColor.IsSame(iDoc.Palette.Colors(CurColNo)) Then DoIt = False End If Next CurSh End If Next CurPg If DoIt Then iDoc.Palette.RemoveColor CurColNoNext CurColNoEnd SubThis even check all pages
Can you provide some more information?
Did you got an error? If Yes: Which message?
I only see a picture with the code and the debugger on. This is a little less to understand the problem!
I asked before if you were calling NudeFan's sub for the active document, and I gave an example of a little sub to do exactly that.
Here's my sub and the sub from NudeFan that it uses.
Sub reset_docpalette() ResetPalette ActiveDocument End Sub Sub ResetPalette(ByRef iDoc As Document) Dim CurColNo As Integer, CurPg As Page, CurSh As Shape, CurSR As ShapeRange, DoIt As Boolean For CurColNo = iDoc.Palette.Colors.Count To 1 Step -1 DoIt = True For Each CurPg In iDoc.Pages Set CurSR = CurPg.Shapes.All If CurSR.Shapes.Count > 0 Then For Each CurSh In CurSR.Shapes If CurSh.Fill.Type = cdrUniformFill Then If CurSh.Fill.UniformColor.IsSame(iDoc.Palette.Colors(CurColNo)) Then DoIt = False End If Next CurSh End If Next CurPg If DoIt Then iDoc.Palette.RemoveColor CurColNo Next CurColNo End Sub
Played around with it abit
found by adding these to the code gets me closer but doesn't work well with Pantone colors.
Tried your code too Eskino but same thing. Works as long as the colors aren't pantones
Oops, Eskino is your cousin. Sorry about that I'm just back from a rather strange medical procedure and I guess I'm still a little loopy
You removed 'ByRef iDoc As Document' from the head line of the routine.I wrote this sub with the intention that you even may use this to handle all open documents.Therefore you can use e.g.:
Sub DoResetAllPalette()Dim CurDoc As DocumentFor Each CurDoc In Application.Documents ResetPalette CurDocNext CurDocEnd SubBut as it looks, you expect to reset the palette only for the active document. Then this is the right additional code:
Sub DoResetThisPalette()ResetPalette ActiveDocumentEnd SubWith that way I programmed it, it is possible to handle not only the active documents. This may be an advantage for higher automated processes. This is something I always have in the back of my mind when creating modules. From my experience: Sooner or later you will need most of the modules later for an extended purpose. This is why I prefer always this way, even if it's not (yet) requested. Maybe it's for someone's a little confusing. I hope, you can excuse it.