Set sys = CreateObject("UltraMon.System")
Set wnd = CreateObject("UltraMon.Window")

deskLeft = sys.DesktopLeft
deskTop = sys.DesktopTop
deskRight = deskLeft + sys.DesktopWidth
deskBottom = deskTop + sys.DesktopHeight
primaryMonId = sys.Monitors("Primary").ID

For Each w In wnd.GetAppWindows(True)
	If (w.Left + w.Width) <= deskLeft Or w.Left >= deskRight Or (w.Top + w.Height) <= deskTop Or w.Top >= deskBottom Then
		w.Monitor = primaryMonId
		w.ApplyChanges 3 'resize to fit and clip to workspace
	End If 
Next
