Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created macro vba in pptm application , my doubt is how to call macro function whenever ppt open, If anybody know please guide me. Thanks in advance.

What I have tried:

VB
Sub Auto_Open()
  
Dim MyPath As String
    Dim MyFile As String
    Dim LatestFile As String
    Dim LatestDate As Date
    Dim LMD As Date
    
    MyPath = "C:\Workspace\OneModernize\April\Mywork\excelAccesssNet\"
    If Right(MyPath, 1) <> "\" Then MyPath = MyPath & "\"
    MyFile = Dir(MyPath & "*.pptm", vbNormal)
    If Len(MyFile) = 0 Then
        MsgBox "No files were found...", vbExclamation
        Exit Sub
    End If
    
    
    Do While Len(MyFile) > 0
        LMD = FileDateTime(MyPath & MyFile)
        If LMD > LatestDate Then
            LatestFile = MyFile
            LatestDate = LMD
        End If
        MyFile = Dir
    Loop
   ' Workbooks.Open MyPath & LatestFile
  If (LatestFile = "Test1234.pptm") Then
  
LMD = CDate(Left(LatestDate, 9))
Dim Expiry As Date
'Expiry = DateValue(Range("A1")) + 7
Expiry = LMD + 7



If LMD > Expiry Then
MsgBox "This File Has Expired. Please Download the latest version!", vbCritical, "File wile close"
Application.DisplayAlerts = False
ActiveWorkbook.Close
Application.DisplayAlerts = True
Application.Quit
Else
MsgBox "You Have " & Expiry - Date & " Day(s) Left", vbInformation, "file  Expires on " & Expiry
End If
End If

End Sub
Posted
Updated 4-May-21 9:47am
v2
Comments
Patrice T 4-May-21 6:58am    
Google is your friend.
manuel_joseph 4-May-21 7:00am    
I tried in google but I didn't get any solutions.

1 solution

Unlike most other Microsoft Office Applications, running a macro on the Open event is not straightforward in PowerPoint.

You can
- download one of the many Add-Ins that can facilitate this
- or do some fancy tricks with a Custom UI component
- OR use Command-line switches

What to do for the various methods are discussed here[^]
 
Share this answer
 
Comments
Maciej Los 4-May-21 15:50pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900