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.
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!
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.
Thank you NudeFan. Yeah, I'm not a programmer but I get by. The code works fine now except with Pantone colors. If I delete all Uniform Fill shapes whereby leaving the Pantone colored shapes then run the macro it deletes all shapes and resets the Palette to no colors(which is the correct behavior given that all shapes are deleted)
NO, that's not correct either. It doesn't delete the pantone colored shapes just resets the DocPalette to no colors at all
That's my problem: I'm very familiar with programming in VBA, but I have only basic knowledge about the entire graphic stuff like different colour systems. That's why I didn't replied until you sent your macro with the Uniform-Colour. This is something where I'm familiar with, so I dared to reply to you. Before I had in mind the huge number of different types of colours and different ways to use them. I know, that this stuff is not easy and you most likely can do this only with limitations and only adapted for certain types of documents.Sorry, I fear, that I can't help you here further.
Not a problem at all. I see it as a learning experience myself. Hell, I don't even need the macro. Just kind of stumbled on the idea. Doubt that I'd ever use it anyway. I'll keep playing with it and see what I come up with.