Michel Bini a écrit :
Samuel Mounier (Liste CGO) a écrit :
mbini a écrit :
Bonjour
Comment insérer la date d'"aujourd'hui" sans quelle change à la
réouverture du classeur, pour avoir un bouton macro qui l'insère.
Cordialement
Michel

Bonjour Michel,

Une petite recherche dans l'archive de la liste et tu trouvera

Ce sujet précis à déjà été abordé (il y a longtemps peut être)

Merci j'ai trouvé
michel
Sub Datefixe
    Dim oDoc as Object, oCell as Object
    oDoc = ThisComponent
    oCell = oDoc.getCurrentSelection()

    'Affectation de la date et heure courante
    oCell.Value = now()
    'Formatage
    Dim aLocale as new com.sun.star.lang.Locale
    Dim oFormats As Object
    Dim sFormat as String
    sFormat = "JJ/MM/AAAA HH:MM:SS"
    oFormats = oDoc.getNumberFormats()
    formatNum = oFormats.queryKey (sFormat, aLocale, TRUE)
    If (formatNum = -1) Then
        formatNum = oFormats.addNew(sFormat, aLocale)
    End If
    oCell.NumberFormat = formatNum
End Sub


Bizarre ce code ne marche pas sur mon install.

J'ai un message d'erreur sur la ligne
        formatNum = oFormats.addNew(sFormat, aLocale)
Pour ma part j'utilise un code généré à partir de l'enregistreur de macro un poil plus simple mais qui n'est pas multilingue par contre

le voici :

sub DateFixe

        dim document   as object
        dim dispatcher as object

        document   = ThisComponent.CurrentController.Frame
        dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

        dim args1(0) as new com.sun.star.beans.PropertyValue

        args1(0).Name = "StringName"
        args1(0).Value = Cstr(Date)
        dispatcher.executeDispatch(document, ".uno:EnterString", "", 0,args1())

        'Application de notre style de cellule date en langue française
        args1(0).Name = "Template"
        args1(0).Value = "Date (fr)"
        dispatcher.executeDispatch(document, ".uno:StyleApply", "", 0, args1())

end sub



Samuel Mounier<BR>
Formateur Centre de Gestion Océan

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Répondre à