Color palette in CorelDRAW 2017 macro

Hi guys

I need to use a palette created from the object with a macro in CorelDRAW 2017, but for some reason the palette created is not updated when I insert a new color and simply hangs everything... i try to close the palette before creating the new updated but only works sometimes, see the code below and if they can give a light on how to solve this I thank you beforehand...

\o/

Sub CreatePalette()

Dim sr As New ShapeRange
Set sr = ActiveSelectionRange

Dim DocColors As Palette
Dim pal As Palette

If sr.Count = 0 Then
MsgBox "Nothing selected!"
Exit Sub
End If

ClosePal

Set pal = Palettes.CreateFromSelection("DocColors", , True)

Err.Clear

End Sub

Private Sub ClosePal()
On Error Resume Next
If Palettes("DocColors").ColorCount <> 0 Then Palettes("DocColors").Close
End Sub