Image with time interval - Excel

3

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 you close by yourself after 1 minute.

    
asked by anonymous 27.10.2017 / 15:15

1 answer

2

Scheduler

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 show the image and the path of the image should be written to strPath

Sub mostrarImagem()
    Debug.Print "mostrarImagem() rodou as " & Time
    On Error GoTo 0
    'INSERIR O CAMINHO DA IMAGEM AQUI
    strPath = "C:/Caminho/do/arquivo/de/Imagem.jpg"
Inicio:
    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"
    Else
        MsgBox "A imagem não pôde ser carregada - Escolha a imagem."
        strPath = EscolherImagem
        GoTo Inicio
    End If
End Sub

Choose the image

This is a function to handle error if the image path does not 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( _
                  msoFileDialogOpen).SelectedItems(1)
        '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
    ActiveSheet.Shapes(1).Delete
    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
    
30.10.2017 / 12:52