Do it in the HMI Tag Table
Had the same question a couple of days ago. Siemens expert told me how to do it. I'm using TIA V13.
Won't work on Event on an HMI button on the screen. You need to do it in the HMI Tag.
HMI Tags/Default tag table. Highlight the tag. At the bottom, go to the Properties/Events tab. You have one choice - "Value Change". The name of your script will be in the dropdown list.
Note that "Value Change" will trigger it twice. Going high, and going low. To avoid the second run, reset the bit within your script at the end.
My tag name is a bool M bit named "RunVB Report".
Last line in my script is:
SmartTags ("RunVB_Report") = False