i

[macro] Tester le contenu d'une cellule



Sub LireCellBis

'=======variables========

dim v_2doc as object, v_2feuille as object, v_2cellTest as object

Dim v_2cellString as string, v_2valueT as variant, v_2cellType as variant

v_2doc=ThisComponent

v_2feuille=v_2doc.sheets.getbyname("Feuille1")

v_2cellTest=v_2feuille.getCellRangeByName("B2")

v_2valueT=v_2CellTest.Value

v_2cellType=v_2CellTest.Type 'pour voir

v_2cellString=v_2CellTest.String

'========================

Select Case v_2valueT

Case 1

msgbox "La cellule contient un nombre"

Case 2

msgbox "La cellule contient du texte"

Case 0

msgbox "La cellule contient l'expression : " +""""+v_2CellTest.string+""""

End Select

End Sub



PYS : Il est recommandé d'utiliser les constantes:

http://api.libreoffice.org/docs/idl/ref/namespacecom_1_1sun_1_1star_1_1table.html#affea688ab9e00781fa35d8a790d10f0e


Par exemple :

select case oCell.Type

case com.sun.star.table.CellContentType.EMPTY

msgbox "cellule vide"

case com.sun.star.table.CellContentType.TEXT

msgbox "texte"

case com.sun.star.table.CellContentType.VALUE

msgbox "nombre"

case com.sun.star.table.CellContentType.FORMULA

msgbox "formule"

end select


select case oCell.Type

case com.sun.star.table.CellContentType.EMPTY

msgbox "cellule vide"

case com.sun.star.table.CellContentType.TEXT

msgbox "texte"

case com.sun.star.table.CellContentType.VALUE

msgbox "nombre"

case com.sun.star.table.CellContentType.FORMULA

msgbox "formule"

end select