Trigger Animation in PowerPoint - vba

I have Microsoft Office PowerPoint 2007. I want to make it so that it will start a specific animation when I press the F4 key. I currently have the following:
Sub DoAnimation()
End Sub
Sub auto_open()
Application.OnKey "{F4}","DoAnimation"
End Sub
So how would I start the animation in the DoAnimation sub?

Related

Powerpoint VBA: Restart each slide

We are building a kiosk. Each slide has a video. Whenever the user navigates or returns to a slide, the video should restart. I have vba code that does this but on 1st run, powerpoint doesn't appear to run the vba. Is there some sort of intialize module I need to add?
Only code:
Public Sub OnSlideShowPageChange(ByVal Wn As SlideShowWindow)
ActivePresentation.SlideShowWindow.View.ResetSlideTime
End Sub

VBA userform now showing in quick access toolbar in excel 2016

I have a userform which I cannot select in the quick access toolbar to add to the ribbon.
All of the other macros I have are visible and can be selected to be added to the quick access toolbar.
I have the name of the userform and command buttons in the userform code matching the name listed within their reposective properties windows.
I have been able to add userforms to previous versions of excel so I am not sure if anything has changed for excel 2016.
Sub userform1_show()
UserForm1.Show
End Sub
Private Sub CommandButton1_Click()
Load.Linux_unix_scan_tab_only
Linux_unix_scan_tab_only.Linux_unix_scan_tab_only
End
End Sub
Private Sub CommandButton2_Click()
Load.unix_SSHkey_tabs
unix_SSHkey_tabs.Linux_unix_scan_and_SSH_Key_trust_tabs
End Sub
Private Sub userform_click()
End Sub

How to implement a Cancel button on a userform?

I have a UserForm with a cancel button.
Sub DialogTest()
MyForm.Show
End Sub
Private Sub CancelButton_Click()
Unload Me
End
End Sub
I also tried MyForm.Hide, End by itself, cmdExit_Click.
The cancel button does not close the dialog nor does it cause the debugger to come up.
I was only able to replicate your issue when the Unload Me Sub was pasted in a Worksheet or Module. When the Sub is in the Userform, it works fine.
Here, the code is pasted in a module and does not close the Userform
Instead, from VBE, double click on your UserForm, then double click on your Cancel Button.
Then paste the code here

How do you create an automatic timer using Excel 2016 VBA macro editor?

I need to create a timer in Excel 2016 VBA editor that will go-off every second and display a message.
I have a simple code that will do just that; however when I run the code a message box appears and then an error follows. My code is presented below:
Private Sub Workbook_Open()
RunEveryTwoMinutes
End Sub
Sub RunEveryTwoMinutes()
MsgBox ("Stop!")
Application.OnTime Now + TimeValue("00:00:01"), "RunEveryTwoMinutes"
End Sub
The error I receive states:
"Cannot run the macro 'C:user|generic\Book1.xlsm'. The macro may not be available in this workbook or all macros may be disabled.
I am not sure what is occurring. I simply need to find out a way to create a one second timer that initiates as soon as the code initializes.
Place this code in your workbook code module:
Private Sub Workbook_Open()
RunEveryTwoMinutes
End Sub
and place this code in a standard code module:
Sub RunEveryTwoMinutes()
MsgBox ("Stop!")
Application.OnTime Now + TimeValue("00:00:01"), "RunEveryTwoMinutes"
End Sub
Alternatively, you can have all the code in your Workbook code module, but you need to qualify the macro name:
Private Sub Workbook_Open()
RunEveryTwoMinutes
End Sub
Sub RunEveryTwoMinutes()
MsgBox ("Stop!")
Application.OnTime Now + TimeValue("00:00:01"), "ThisWorkbook.RunEveryTwoMinutes"
End Sub
I believe the first method is preferable.

Calling a macro from a button in edit mode while in PowerPoint

I'm trying to write a vba macro that can be called in edit-mode in PowerPoint 2007-2010.
I can easily add a Command Button to a presentation. However, this button can only be clicked to trigger the vba macro while in slideshow mode.
However, what I would like to do is have this button trigger the associated vba macro while in edit mode. Clicking on it in edit mode allows me to change its size etc, but it doesn't call the macro.
In Excel on the other hand, I get exactly the expected behaviour when I insert a button -> clicking on it calls the vba action.
So how can I create a button (or other element that acts the same way) that calls a vba macro during edit view in PowerPoint. The only way I can think of is using a ribbon action, however this is unpractical in this case, because the macro will modify a shape that is associated with the button and there might be several of these shapes per slide that should each have their own button.
The only way I can think of is using a ribbon action, however this is unpractical in this case, because the macro will modify a shape that is associated with the button and there might be several of these shapes per slide that should each have their own button.
Depending on what you're trying to do, a ribbon button that launches a macro might be quite practical. The macro could operate on the current selection (and test the current selection to ensure that it's something appropriate).
With ActiveWindow.Selection.ShapeRange
' operate on the currently selected shapes
End with
just answer it a some where else also
it is possible to do so all you need is download this file
http://www.officeoneonline.com/eventgen/EventGen20.zip
install it
create a class module
paste this code
Option Explicit
Public WithEvents PPTEvent As Application
Private Sub Class_Initialize()
End Sub
Private Sub PPTEvent_WindowSelectionChange(ByVal Sel As Selection)
If Sel.Type = ppSelectionShapes Then
If Sel.ShapeRange.HasTextFrame Then
If Sel.ShapeRange.TextFrame.HasText Then
If Trim(Sel.ShapeRange.TextFrame.TextRange.Text) = "Text inside your shape" Then
Sel.Unselect
yoursub
End If
End If
End If
End If
End Sub
insert a new module
paste this code
Dim cPPTObject As New Class1
Dim TrapFlag As Boolean
Sub TrapEvents()
If TrapFlag = True Then
MsgBox "Already Working"
Exit Sub
End If
Set cPPTObject.PPTEvent = Application
TrapFlag = True
End Sub
Sub ReleaseTrap()
If TrapFlag = True Then
Set cPPTObject.PPTEvent = Nothing
Set cPPTObject = Nothing
TrapFlag = False
End If
End Sub
Sub yoursub()
MsgBox "Your Sub is working"
End Sub
Now run TrapEvents and whenver you will click shape with that text in it your sub will run
Credits to the person who wrote this http://www.officeoneonline.com/eventgen/eventgen.html