Just select the button tool from the menu and using the wizard, set it up as a Close button. Then just replace the close button code with whatever your code is. If you code is in a function or sub you can call it using:
MyFunction
or
Result = MyFunction()