3

I need to schedule a piece of VBA code to run each 500 ms in Microsoft PowerPoint for Mac (version 16).

In Word and Excel, I can use the Application.OnTime method to schedule code, but this method doesn't exist in PowerPoint and has a granularity of 1 second anyway.

On Windows, I can use an external call to the SetTimer function in the user32 library, as done, for example, in this question. However, I can't seem to find an equivalent library method on macOS.

My best bet seems to be to write a utility library with an interface similar to SetTimer on Windows implemented using for example NSTimer, Grand Central Dispatch, or a Pthread, installing it, then calling it from VBA and having it call back on an interval.

My Mac development experience is limited and my experience writing and calling external libraries from VBA is non-existent, but I have managed to get a round trip call/callback to a C/Objective-C library working (essentially void CallFunction(void (*function_pointer)(void)) { function_pointer(); } called as CallFunction(AddressOf Callback)), but when I try to defer that callback via Grand Central Dispatch or a Pthread, PowerPoint crashes as soon as the callback happens with a EXC_BAD_ACCESS exception and a log I can't easily decipher. I could imagine the problem being that the callback happens from another thread or that the callback function isn't at the address it was at when AddressOf was called.

Is there a ready-made solution to schedule VBA code in PowerPoint for Mac? Alternatively, are there any resources that could help me debug the callback crashes?

Jacob Bundgaard
  • 943
  • 11
  • 29

0 Answers0