I am working on a VBA project which links Excel with SAP FrontEnd.
Bla bla bla... I discovered a problem whereby I can't remove focus from a Userform Button after clicking on a Msgbox prompt or when another sub-Userform is loaded.
Yes, I tried using SetFocus to another Control, putting the whole object reference i.e. Userform1.Button1.SetFocus, setting a dirty Boolean to terminate, setting another event etc... yet it still didn't work. No error was thrown by VBA though, but there was a problem since there is another procedure to disable the darn Button after pressing 'No' in the Msgbox prompt or cancelling the sub-Userform. Basically, in the scenario I was testing, I end up with a disabled Button which has focus. Weird and everything else stuck except for the Esc key.
After two sleepless nights trying to figure a workaround, I was still unable to solve this issue.
Yes, I googled too... that is the first thing anyone will do when stuck with a problem isn't it? Anyway, if someone has discovered the solution out there, it will probably end up in page 2 or 3 (or further down...)
Finally just now, I discovered the solution: a Control property which is rarely mentioned in VBA books: TakeFocusOnClick.
I set it to False and voila! Problem solved!
I also I discovered how to reactivate Excel window after SAP CreateSession on an active GuiSession object.
I tried AppActivate and even an API call procedure which I don't even understand but Excel icon will only blinks on the taskbar. Excel did not actually open back and I still see the ugly SAP interface.
Solution was using GuiMainWindow.Iconify method. It minimizes the SAP GUI window and I got what I wanted.
Ah, two simple solutions for problem I was having for days.
Puas.
No comments:
Post a Comment