Time Lapse Image – Excel


I need to assign an image that appears every 1 hour in EXCEL, how?! You will probably need to use VBA. But I'm not very familiar.

And that it closes by itself after 1 minute.



Use this VBA code to schedule tasks at the desired time:

Private Sub Workbook_Open()
    '-- Roda os Subs ou funções no horário agendado.
    'Deve ser colodado em EstaPastadeTrabalho

    Application.OnTime TimeValue("10:00:00"), "mostrarImagem"
    Application.OnTime TimeValue("12:00:00"), "mostrarImagem"
    Application.OnTime TimeValue("14:00:00"), "mostrarImagem"
End Sub

Show Image

This is used to display the image and the path of the image must be written in strPath

Sub mostrarImagem()
    Debug.Print "mostrarImagem() rodou as " & Time
    On Error GoTo 0
    strPath = "C:/Caminho/do/arquivo/de/Imagem.jpg"
    If Dir(strPath) <> "" Then
        ActiveSheet.Pictures.Insert (strPath)
        Application.ScreenUpdating = False
        Application.DisplayFullScreen = True
        Application.DisplayFormulaBar = False
        ActiveWindow.DisplayWorkbookTabs = False
        ActiveWindow.DisplayHeadings = False
        ActiveWindow.DisplayGridlines = False
        Application.OnTime Now() + CDate("00:01:00"), "fecharImagem"
        MsgBox "A imagem não pôde ser carregada - Escolha a imagem."
        strPath = EscolherImagem
        GoTo Inicio
    End If
End Sub

choose image

This is a function to handle error if the image path doesn't find anything.

Public Function EscolherImagem() As String
    'Créditos: http://software-solutions-online.com/excel-vba-open-file-dialog/
    Dim intChoice As Long
    Dim strPath As String

    'only allow the user to select one file
    Application.FileDialog(msoFileDialogOpen).AllowMultiSelect = False
    'make the file dialog visible to the user
    intChoice = Application.FileDialog(msoFileDialogOpen).Show
    'determine what choice the user made
    If intChoice <> 0 Then
        'get the file path selected by the user
        strPath = Application.FileDialog( _
        'print the file path to sheet 1
        EscolherImagem = strPath
    End If
End Function

close image

This Sub is called 1 minute after inserting the image.

Sub fecharImagem()
    'Sub agendado irá rodar por 1 minuto
    Application.DisplayFullScreen = False
    Application.DisplayFormulaBar = True
    ActiveWindow.DisplayWorkbookTabs = True
    ActiveWindow.DisplayHeadings = True
    ActiveWindow.DisplayGridlines = True
    Application.ScreenUpdating = True

    Debug.Print "mostrarImagem() parou as " & Time
End Sub
Scroll to Top