One approach I've used in the past is to dynamically build the entire POLYLINE formula as a string and push it into your target cell as required. Have a look at the following post where I built a Sparkline shape using this technique:
http://visualsignals.typepad.co.uk/vislog/2009/05/simple-visio-sparkline-implementation.html