How to create a PowerPoint timer? - vba

I have to complete a timer in PowerPoint, it counts down for a specificed amount of time when a shape on particular slide is clicked. I heard macros could be a way to do this, but I have very little knowledge about them. With my research I was able to add a macro and pop out a message box when a shape is clicked.
How can I implement a timer with this? VBA syntax is pretty unfamiliar to me. What happens after timer finishes is another question though.

Ok this is a late answer but for the people coming across such task, I got over this using custom animations in PowerPoint instead of doing it with macros. There is variety of things you can do with animations so it's probably better for you to search internet for specifically what you want to do.

Related

VBA PPT Event triggered when chart is added

I am trying to write an VBA-Code that triggers whenever a chart is added in PPT. So far I found
this list: Link. However the options don't work, I thought maybe using "AfterShapeSizeChange", since it comes kind of close. But even this event does not work/trigger.
Anybody has an idea what I could use?
Kind regards

Unding Macro actions made during a SlideShow

I want to ask about something, that can probably get pretty complex. I'm working on an interactive presentation with some game elements (stuff that use variables, a timer, score, etc.) and I've noticed that any changes a macro makes (changing the string in a text box, disabling certain shapes) when you run a slide show remain after the slide show has finished. Given that the presentation and the games therein are made to be played multiple times, I would like to avoid having the user click "Undo" a million times or closing and opening the presentation again. I am not sure how to go about this, but I've had a few ideas:
The first one was to track every change that's being made, while the game is running and then have a macro use the "Undo" command the required number of times, once the slideshow is stopped. Creating an Event Handler however proved to be rather complicated. I'm not that well versed in VBA and reading how many declarations, classes and whatnot have to be made, the fact that I cannot find in the reference what the Event for simply ending the slideshow is (that is, when the user presses Esc, not when the last slide has been reached) not to mention the fact that it's very easy to make a mistake that can render all of that code useless, makes me think this is needlessly complicated just for a single event.
Another idea was to set the initial values of the properties that are to be changed during the game, along with the needed variables at the start of the game, so that no matter what changes are made in the presentation, the values will always be reset when running it, although that would make it tedious to tweak things and make big changes to the game, when needed.
Can you give me some suggestions on how I should go about this problem? Which method would be better? Is there some way to make it so that nothing a macro does during a slide show makes actual changes to the presentation itself? I'd very much like to hear your thoughts.
Thanks!

Using Excel while macros are running

There are a half-dozen answers to this. "Open a second instance" "Have a pause" Etc. I'm not looking for that.
I'm looking for the user of the workbook to be able to manipulate the workbook while the macro is running. I've seen this working before, where the user could scroll around, change tabs, even add and remove data, all while the macro was running. Unfortunately, I couldn't get permission to look at the code (And committing CFAA violations ins't my cup of tea), so I have no idea how they did it.
How can you enable a user to edit the workbook as macros are running? For a specific example, I have Conway's Game of Life running. Users select cells to flip live/dead, then can run a macro to run the entire thing. I think it'd be nice for users to be able to change cells as the macro is running. (which is a second on select macro)
Thank you
Sorry just reread the question. I wouldn't expect the permutation to run for very long - not long enough to interrupt really.
But if it does, then the advice about using lots of DoEvents stands.
The other option is that you can use the OnTime event to have a "heartbeat"
VBA Macro On Timer style to run code every set number of seconds, i.e. 120 seconds
You can set the timer to say 3 seconds. Every time the OnTime event occurs you do one step of your permutation. In the three seconds in between they can edit.
Refactor your macro to use Events. In which case, you would have a series of event handlers (instead of one monolithic macro) to respond to various triggers. This is assuming that the macro is influenced by what the user is doing in the worksheet.
One way of (sort of) doing this is to use a Modeless Userform (UserForm.Show vbModeless)
The user form stays visible but the VBA stops running when the form is shown and the user can then interact with Excel. Then when the user clicks a button on the form the code behind the button starts running again.
So in reality the user is either interacting with Excel or interacting with the form ...

MS Word RibbonX How can I dynamically populate a combobox when a dotm file opens?

I'm a little stumped here. I'm diving deeper into designing ribbons for MS Word 2010, and I came across something new: populating comboboxes on the fly. In the image below, you can see...
...that I'm a dude who likes music while he works, just like any other dude. Problem is my list of playlists changes from time to time, so I don't want to hard-code that list into my ribbon's combobox. I can easily hard-code it, but I want this thing to be dynamic. And so, in my ribbon code:
<comboBox id="cmbPLaylist" label="Playlist" getItemLabel="Document_Open">
<item id="none" label="None"/>
</comboBox>
I have left only one item, "none," which is fine if I want the music player to launch with no playlist loaded. But what if I want a playlist to automatically load?
First, from my Google and book research, I've determined that I need to have a getItemLabel callback to populate the control. Is this the right way to go? But how do I run that automatically when my Normal.dotm loads? I'm having problems running this thing in the Document_Open event, and I've been reading online that I'm not alone.
My problem is a bit threefold: first, I'm really new at using these predefined callbacks like getEnabled, getItemLabel, etc. The callback territory is a very new territory for me. Second, I've never used a combobox in a ribbon before. Three, I've never dynamically populated a combobox in a ribbon before. I might be trying to bite off more than I can chew at once, but can anyone point me in the right direction?
My code so far, inserted into my Normal.dotm Document_Open event, is such:
Private Sub Document_Open(control As IRibbonControl, ByRef label)
Dim ListOfPlaylists() As String
ListOfPlaylists = GetPlaylists()
ListOfPlaylists(UBound(ListOfPlaylists)) = "Random"
End Sub
After this, I'm stumped. As you can see, I'm not sure how to tell MS Word, "Hey, MS Word, insert this value into the combobox list!"
Maybe it's my newbness at this whole thing, but when I Google for an answer, I'm not seeing it in the code. So any help is appreciated. Thanks!
I actually did some fiddling and almost stumbled on the answer. I put this in my code and it seems to work just fine now:
Sub drpPlaylists_getItemCount(Control As IRibbonControl, ByRef drpPlaylists_itemCount)
drpPlaylists_itemCount = UBound(ReadDirectoryContents(MusicDirectory, "*.m3u"))
End Sub
I guess this gets launched every time the ribbon has to reload itself. But it's solved for now. Still have some things to study up on on when these callbacks get called, but I'll figure this out. Thanks for the help!

How to update an Access VBA app with 30 forms?

I need to update an Access VBA app with around 30 forms in it.
I have to amend a screen that seems to have been set up right at the start of the app, it uses a lot of SQL tables. Is there an way of finding my way to the start of the code?
I come from a procedural coding background and I am unused to code that doesn't have a start and an end; I also know a bit of VB, some ASP, some .Net and general computing.
When something "automagically" happens upon opening an Access database, it is almost always because
A "startup form" has been specified. (In Access_2010 that's done in File > Options > Current Database > Display Form.) ...or...
The database has a Macro named AutoExec which is automatically run when the database is opened (unless you bypass it by holding the [Shift] key down while opening).
In addition to #Gord's answer, there's a few things you need to know. I'm going to give you the quick & dirty version.
First, there's 2 types of code in Access. VBA & macros. Sometimes what's called a macro, is really VBA.
In Access, a macro is a set of instructions to do something to the database. It's very limited in what it can do. These are often used by novices who don't know how to program in VBA.
VBA is the real powerhouse behind the scenes. It can do everything a macro can do, but a whole lot more.
Access uses an Event-Driven / Object-Oriented (at least close enough for this discussion) interface. Do a Google search on those meanings. But very quickly, the listbox on a form is an object. It has properties (like width), methods (add an item), and events (click on an item).
To see the code, for macros look to to your navigation window to your left. For VBA (modules), look to the same window, or just press Alt-F11. VBA can be used standalone in a module, or behind the scenes of a form or report.
Once you get the hang of it, you'll find Access to be a handy RAD tool for small projects.
Good luck.
It appears that you already have found the form that opens when the app starts (if not, check out Gord Thompson's answer).
The first things that happen when an Access Form opens (the "start of the code", as you called it) are the Load and Open events.
If there is any code in this form that is connected to these events, then it's in the Form_Load() and Form_Open() functions in the code of the form.