Gérard Laloux a écrit :
Yeps,
J'aimerais pouvoir reprendre une discussion entamée sur users avec Christian alias "Christianwtd".
>> Macro destinée à supprimer des caractères accentués.
Merci Christian, cela correspond /pratiquement/ à ce dont j'ai besoin.
/++ Quelques questions dans le code que tu m'as envoyé >>/

Sub SupprimeAccents
   Dim oDocument As Object, oSheet As Object
   Dim oCell As Object
    Dim Col As Integer, Lig As Integer, i As Integer
    Dim LigDeb As Integer, LigFin As Integer
  '
    Col = 0
   /J'aimerais pouvoir faire exécuter la macro sur plusieurs colonnes
Je suppose que pour cela, il "envelopper" le "for next" des lignes par un autre "for next" pour les colonnes ??
/     LigDeb = 0
    LigFin = 100      '
    oDocument=ThisComponent
    /oSheet=oDocument.currentController.ActiveSheet
//J'ai modifié la ligne ci-dessus pour que la macro s'exécute quelle que soit la feuille/
  '
    For i = LigDeb to LigFin
       Txt = oSheet.getCellByPosition(Col, i).getString
        Nc = Len(Txt)
        For n = 1 to Nc
            Car = Mid(Txt, n, 1)
            If Car = "é" Or Car ="è" Or Car = "ê" Or Car = "ë" Then
                Car = "e"
                Mid(Txt, n, 1) = Car
                oSheet.getCellByPosition(Col, i).setString(Txt)
/Pourquoi cette dernière ligne n'est-elle pas présente dans le elseif suivant ??/
            ElseIf Car = "â" Or Car ="à" Or Car ="ä" Then
                Car = "a"
                Mid(Txt, n, 1) = Car
            ElseIf Car = "ï" Or Car ="î" Then
                Car = "i"
                Mid(Txt, n, 1) = Car
oSheet.getCellByPosition(Col, i).setString(Txt) ElseIf Car = "_" Or Car ="-" Then
                Car = ""
                Mid(Txt, n, 1) = Car
                oSheet.getCellByPosition(Col, i).setString(Txt)
                Nc = Nc - 1
            Endif
        Next n
    Next i
End Sub

Bon dimanche,
----------
Gérard Laloux
B - 6210 Rèves
----------

Bonjour Gérard,

La macro du dimanche :-)


Sub SupprimeAccents
    Dim oDocument As Object, oSheet As Object
     Dim Col As Integer, Lig As Integer
     Dim x As Integer, y As Integer
     Dim LigDeb As Integer, LigFin As Integer
     Dim ColDeb As Integer, ColFin As Integer
     Dim Txt As String
   '
   ' variables à modifier
     LigDeb = 0
     LigFin = 100
     ColDeb = 0
     ColFin = 1
     '
     oDocument=ThisComponent
     oSheet=oDocument.currentController.ActiveSheet
   '
     For y = ColDeb To ColFin
         For x = LigDeb to LigFin
            Txt = oSheet.getCellByPosition(y, x).getString
             Nc = Len(Txt)
             For n = 1 to Nc
                 Car = Mid(Txt, n, 1)
                 If Car = "é" Or Car ="è" Or Car = "ê" Or Car = "ë" Then
                     Car = "e"
                     Mid(Txt, n, 1) = Car
                     oSheet.getCellByPosition(y, x).setString(Txt)
                 ElseIf Car = "â" Or Car ="à" Or Car ="ä" Then
                     Car = "a"
                     Mid(Txt, n, 1) = Car
                     oSheet.getCellByPosition(y, x).setString(Txt)
                 ElseIf Car = "_" Or Car ="-" Then
                     Car = ""
                     Mid(Txt, n, 1) = Car
                     oSheet.getCellByPosition(y, x).setString(Txt)
                     Nc = Nc - 1
                 Endif
             Next n
         Next x
     Next y
End Sub


J'ai remplacé la variable i par x et y. C'est plus causant.
Tu peux ajouter des commentaires (pour toi) dans le listing, mais précédé d'une apostrophe (pas d'une barre) ActiveSheet c'est bien, mais attention au risque de faire du n'importe quoi sur une mauvaise feuille. Détail : la macro fonctionne sur des cellules contiguës. Si par hasard tu fais une colonne sur 2 par exemple, il faudra faire :
For y = ColDeb To ColFin Step 2

Je crois que j'ai tout dit.

Bon surf,
Christian

--
Visitez http://christianwtd.free.fr/ pour débuter avec Calc, d'OpenOffice.org

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

Répondre à