

![]() | Start a set with this search |
![]() | Include this search in one of my sets |
![]() | Exclude this search from one of my sets |
![]() | Permalink to these results Paste this link in email or IM: |
| Atom feed for tracking future search results Paste this URL into your reader: |
6 messages in org.openoffice.fr.progPremière fonction| From | Sent On | Attachments |
|---|---|---|
| Jean Sympa | Dec 22, 2006 4:48 am | |
| emma...@fr.thalesgroup.com | Dec 22, 2006 4:58 am | |
| Laurent Godard | Dec 22, 2006 5:06 am | |
| Paul Veuve | Dec 22, 2006 5:21 am | |
| Laurent Godard | Dec 22, 2006 5:47 am | |
| Bernard Marcelly | Dec 22, 2006 11:27 am |

![]() | Permalink for this message Paste this link in email or IM: |
![]() | Permalink for this thread Paste this link in email or IM: |
| Atom feed for this thread Paste this URL into your reader: |
| Subject: | Première fonction | Actions... |
|---|---|---|
| From: | Jean Sympa (jsy...@free.fr) | |
| Date: | Dec 22, 2006 4:48:28 am | |
| List: | org.openoffice.fr.prog | |
Bonjour à toutes et à tous,
Première fonction
Je sais que mon exemple et celui d'un débutant: C'est en forgeant que l'on devient forgeron
Objectif : Créer une fonction en partant d'une macro mise au point.
//---- Macro ayant servi de point de départ
-------------------------------------------
Cette macro remplace une seule sous chaîne de caractère par un caractère. Je la transforme en une fonction pour pouvoir remplacer non pas une Sous Chaîne mais autant de Sous chaîne qu'il est nécessaire.
Option Explicit
Sub RemplacerSChParCar()
Dim monDocument as Object
Dim jeCherche As Object, trouv As Variant
Dim x As Long
monDocument=ThisComponent
jeCherche=monDocument.createSearchDescriptor
with jeCherche
.SearchString= "=E8"
.SearchWords=false
end with
trouv=monDocument.findAll(jeCherche)
print "Nombre d'occurences: " & cstr(trouv.count)
for x=0 to trouv.count-1
trouv(x).CharBackColor=1234567 'Fond vert sombre
next
End Sub
Les changements de chaîne ont lieu dans des documents de ce type :
Le père parle à son fiston de 5 ans=20
- Tu dois manger tous les épinards si tu veux devenir fort comme papa.=20 - Non. Je ne veux pas être fort comme toi. Je veux être boss comme maman= =20 ****
La ma=EEtresse d'école...=20 - Popaul, douze bouteilles de vin à 20$ chacune, combien =E7a fait?=20 - =C0 la maison, si c'est pour mon papa, Guy-Marie, =E7a fait 3 jours,=20 mademoiselle.=20
Rem ---------------------------------------------------------------
Fonction créée
Option Explicit
Function Remplacer1SChPar1Car(Sch As String, Car As String)
Dim monDocument as Object
Dim jeCherche As Object, trouv As Variant
Dim x As Long
monDocument=ThisComponent
jeCherche=monDocument.createSearchDescriptor
with jeCherche
.SearchString= Sch
.SearchWords=false
end with
trouv=monDocument.findAll(jeCherche)
'print "Nombre d'occurences: " & cstr(trouv.count)
for x=0 to trouv.count-1
trouv(x).CharBackColor=1234567 'Fond vert sombre
trouv(x).String=Car
next
End Function
Rem --------------------------------------------------------------------
Je lance cette macro, sans succès. Est-ce que j'ai bien écrit les paramètres de la fonction?
Sub RemplacerNSChParNCar()
Remplacer1SChPar1Car("=20", " ")
End Sub
Je n'ai pas trouvvé l'erreur et pourtant je l'ai bien cherchée.
Avec mes remerciements
Cordialement
Papy







