Xiaxiang,
Ron's routine needs a polyline boundary to extend the linework to..so as-is, you can get your desired result by drawing a polyline boundary enclosing your lines and circles and deleting it afterwards OR by making the two vertical lines polylines and including them in your selection...still less work then all the trimming and extending you would have to do without it.
If you want to do it programmatically, you could search how to create a bounding box out of multiple elements and modify the code to use the bounding box created.
**EDIT**
Also note that by extending multiple lines at the same vertical position, you will end up with overlapping lines.