This can be A Embeded macro file that Is written in VBA
or a COMServer based one that is controlled by an addin.
MacroFeatures are the most powerful thing in solidworks in my opinion.
since you are using macros currently you will want to use the VBA method
start with this macrofeature code
its a pain to get started with for the first time so ask questions as you start to develop this.
use the above template for formatting purposes.
Thank you everyone for the suggestions.I will try it out.
I could manage to do it.
This document is very useful, especially the empty macrofeature code.
It contains also a very helpful presentation about Macrofeatures