Je débute et après quelques recherches j'ai testé deux macros qui fonctionnent et font la même chose alors que la seconde est bien plus coute.
Quel est la bonne solution
Code : Tout sélectionner
Sub insertDate
'insere la date en position cellule selectionnée
Dim aLocale as new com.sun.star.lang.Locale, vNumFormat
Dim oDoc as Object : oDoc = ThisComponent
Dim oCell as Object : oCell = oDoc.CurrentSelection 'celulle selectionnée
Dim sFormat as String : sFormat = "JJ/MM/AA"
If oCell.supportsService( "com.sun.star.sheet.SheetCell" ) Then
oCell.setValue( Now() )
vNumFormat = oDoc.getNumberFormats().queryKey( sFormat, aLocale, TRUE )
If ( vNumFormat = -1 ) Then
vNumFormat = oDoc.getNumberFormats().addNew( sFormat, aLocale )
End If
oCell.NumberFormat = vNumFormat
msgbox vNumFormat '=>30
End If
End Sub
Code : Tout sélectionner
sub insertdate2
Dim oDoc as Object : oDoc = ThisComponent
Dim oCell as Object : oCell = oDoc.CurrentSelection 'cellule selectionnée
ocell.value=Now()
ocell.NumberFormat=37 'jj/mm/aaaa 30 ou 36 jj/mm/aa 37
end sub
La modération vous a écrit: Merci d'utiliser les balises [code] pour mettre en forme vos macros et les rendre ainsi plus lisibles.