Results 1 to 8 of 8

Thread: VBA function running continuously in PowerPoint?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #8
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,743
    Location
    1. I used a timer API that starts when the Slide SHow Start event fires. You need a Class for that

    Option Explicit
    
    
    Public WithEvents App As Application
    
    
    'Private Sub App_PresentationClose(ByVal Pres As Presentation)
    '    IsTimerOff = True
    '    Call TimerOnOff
    'End Sub
    '
    'Private Sub App_PresentationOpen(ByVal Pres As Presentation)
    '    IsTimerOff = False
    '    Call TimerOnOff
    'End Sub
    
    
    Private Sub App_SlideShowBegin(ByVal Wn As SlideShowWindow)
        IsTimerOff = False
        Call TimerOnOff
    End Sub
    
    
    Private Sub App_SlideShowEnd(ByVal Pres As Presentation)
        IsTimerOff = True
        Call TimerOnOff
    End Sub
    2. I used a different connection sub since my AV didn't like yours

    'https://www.access-programmers.co.uk/forums/threads/vba-code-to-check-internet-connection-in-windows-os-64-bit-vba-ms-access-2019.320847/
    Option Explicit
    
    
    Public Flg As LongPtr
    Public Declare PtrSafe Function InternetGetConnectedState _
        Lib "Wininet.dll" (lpdwFlags As LongPtr, _
        ByVal dwReserved As Long) As Boolean
    
    
    Private Const INTERNET_CONNECTION_MODEM As Long = &H1
    Private Const INTERNET_CONNECTION_LAN As Long = &H2
    Private Const INTERNET_CONNECTION_PROXY As Long = &H4
    Private Const INTERNET_CONNECTION_OFFLINE As Long = &H20
    Private Const INTERNET_CONNECTION_MODEM_BUSY As Long = &H8
    Private Const INTERNET_RAS_INSTALLED As Long = &H10
    Private Const INTERNET_CONNECTION_CONFIGURED As Long = &H40
    
    
    Function IsInternetOk() As Boolean
        Dim INTNET As Long
    
    
        INTNET = InternetGetConnectedState(Flg, 0&)
    
    
        If Flg >= INTERNET_CONNECTION_OFFLINE Then
            Debug.Print "INTERNET_CONNECTION_OFFLINE"
        End If
    
    
        If CBool(INTNET) Then
            IsInternetOk = True
        Else
            IsInternetOk = False
        End If
    End Function

    3. The main code and the color changing is in another module. I really couldn't test the connected / not connected part, i just wanted to see the timer part

    ' --------------------------------------------------------------------------------
    ' Copyright ©1999-2018, Shyam Pillai, All Rights Reserved.
    '   http://skp.mvps.org/ppt00021.htm
    '--------------------------------------------------------------------------------
    ' You are free to use this code within your own applications, add-ins,
    '
    ' documents etc but you are expressly forbidden from selling or
    ' otherwise distributing this source code without prior consent.
    ' This includes both posting free demo projects made from this
    ' code as well as reproducing the code in text or html format.
    '
    '--------------------------------------------------------------------------------
    
    
    Const NumSeconds As Long = 3
    
    
    Option Explicit
    
    
    'API Declarations
    Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
     
    ' Public Variables
    Public TimerID As Long
    Public IsTimerOff As Boolean
    
    
    
    
    Sub TimerOnOff()
    
    
        If IsTimerOff = False Then
             TimerID = SetTimer(0, 0, NumSeconds * 1000, AddressOf TimerProc)
    
    
             If TimerID = 0 Then
                 MsgBox "Unable to create the timer", vbCritical + vbOKOnly, "Error"
                Exit Sub
            End If
    
    
            IsTimerOff = True
    
    
        Else
            TimerID = KillTimer(0, TimerID)
    
    
            If TimerID = 0 Then
                MsgBox "Unable to stop the timer", vbCritical + vbOKOnly, "Error"
            End If
    
    
            IsTimerOff = False
        End If
     End Sub
    
    
     
    Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long)
        
        Dim hshp As Shape
        Dim osld As Slide
        
        'for testing
        ActivePresentation.Slides(1).Shapes("Test").TextFrame.TextRange.text = Format(Now, "hh:mm:ss")
        
        
        For Each osld In ActivePresentation.Slides
            For Each hshp In osld.Shapes
                With hshp
                    If Not .Name Like "GoogleShape*" Then GoTo NextShape
                                          
                    Select Case IsInternetOk
                        Case True
                            .Fill.ForeColor.RGB = RGB(255, 255, 255)
                            .Fill.Solid
                        Case False
                          .Fill.ForeColor.RGB = RGB(50, 50, 50)
                          .Fill.Solid
                    End Select
                End With
    NextShape:
            Next hshp
        Next osld
    End Sub
    4. I used the CustomUI onload to initialize the class

    <?xml version="1.0" encoding="utf-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="InitializeApp">
    </customUI>
    Attached Files Attached Files
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •