Check that the ArcToolbox dockable window has been created (open) by comparing the handle of IArcToolbox againts zero. Change the line: arcToolbox.RemoveToolbox gpToolboxBy: If (Not (arcToolbox.hWnd = 0)) Then arcToolbox.RemoveToolbox gpToolbox End If