• User Attivo

    Excel/Calc funzione tramite macro

    Ciao a tutti volevo chiedervi se è possibile ad esempio registrare una funzione tramite il registratore di macro, collegare la macro ad un pulsante che alla pressione esegue la funzione.
    Nel dettaglio, io ad esempio vorrei creare un pulsante che esegue la funzione =adesso() e mi stampa data ed ora corrente nella cella in cui sono.
    Mi è venuto in mente di provare a registrare la macro mentre premo i pulsanti ed eseguo la funzione ma già eseguendo la macro dalla console vba mi da errore:
    Errore di sintassi BASIC, era previsto un simbolo.
    Il codice che crea è questo:

    
    REM  *****  BASIC  *****
    
    Private Sub
    
    End Sub
    
    
    sub Main
    rem ----------------------------------------------------------------------
    rem define variables
    dim document   as object
    dim dispatcher as object
    rem ----------------------------------------------------------------------
    rem get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    
    rem ----------------------------------------------------------------------
    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "StringName"
    args1(0).Value = "="
    
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())
    
    rem ----------------------------------------------------------------------
    dim args2(0) as new com.sun.star.beans.PropertyValue
    args2(0).Name = "ToPoint"
    args2(0).Value = "$P$15"
    
    dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args2())
    
    
    end sub
    
    
    sub Adesso
    rem ----------------------------------------------------------------------
    rem define variables
    dim document   as object
    dim dispatcher as object
    rem ----------------------------------------------------------------------
    rem get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    
    rem ----------------------------------------------------------------------
    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "StringName"
    args1(0).Value = "=adesso()"
    
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())
    
    
    end sub
    
    
    sub data_odierna
    rem ----------------------------------------------------------------------
    rem define variables
    dim document   as object
    dim dispatcher as object
    rem ----------------------------------------------------------------------
    rem get access to the document
    document   = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    
    rem ----------------------------------------------------------------------
    dim args1(0) as new com.sun.star.beans.PropertyValue
    args1(0).Name = "StringName"
    args1(0).Value = "=adesso()"
    
    dispatcher.executeDispatch(document, ".uno:EnterString", "", 0, args1())
    
    
    
    

    Grazie a tutti nel caso, ciao!