Bonjour à tous, et merci de m'accueillir sur ce forum,
Je vous expose mon souci... Je travaille avec des élèves aveugles dans les collèges et lycées et mon boulot est de faciliter leur intégration dans leur classe et leur autonomie.
J'avais créé entre autres macros, sous MS Word alors majoritairement utilisé dans mon académie, une permettant de "nettoyer" un fichier texte donné par le professeur afin de l'adapter au mieux à une lecture en Braille (écriture pour personne aveugle), que ce soit après impression ou sur un terminal Braille.
Plusieurs de mes élèves étant passés (et c'est très bien) à Open Office, il me faut transposer rapidement cette macro du VBA au Basic utilisé dans OO, et je n'y connais rien. Promis, je vais m'y mettre, mais si, pour accélérer le processus, une âme charitable et compétente pouvait me mettre sur la voie... Je vous en remercie d'avance.

La macro en VBA :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
Sub NettBraille()
'
' Macro créée par Franck A en 2015
'------------------------------------------------------------------------
'Cette macro a pour rôle de nettoyer un texte
'en vue d'une lecture en braille sur plage tactile
'en supprimant les codes de mise en forme "noir"
'et en ajustant les règles typographiques au Braille.
'Elle doit être utilisée avant d'appliquer les
'macros d'abrègement.
'------------------------------------------------------------------------
'
'Coupe le texte et le recolle en supprimant la mise en forme.
Selection.WholeStory
Selection.Cut
Selection.PasteSpecial Link:=False, DataType:=wdPasteText, Placement:= _
wdFloatOverText, DisplayAsIcon:=False
Selection.WholeStory
Selection.HomeKey Unit:=wdLine
'Désactive la fonction de correction automatique
Options.AutoFormatAsYouTypeReplaceQuotes = False
' Remplace les sauts de section par des sauts de page manuel
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "^12"
.Replacement.Text = "^m"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
' Modifie la mise en page (A4, marges, orientation, etc.)
With ActiveDocument.Styles(wdStyleNormal).Font
If .NameFarEast = .NameAscii Then
.NameAscii = ""
End If
.NameFarEast = ""
End With
With ActiveDocument.PageSetup
.LineNumbering.Active = False
.Orientation = wdOrientPortrait
.PaperSize = wdPaperA4
.TopMargin = CentimetersToPoints(2)
.BottomMargin = CentimetersToPoints(1)
.LeftMargin = CentimetersToPoints(2)
.RightMargin = CentimetersToPoints(1)
.Gutter = CentimetersToPoints(0)
.HeaderDistance = CentimetersToPoints(1)
.FooterDistance = CentimetersToPoints(1)
.FirstPageTray = wdPrinterDefaultBin
.OtherPagesTray = wdPrinterDefaultBin
.SectionStart = wdSectionNewPage
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.VerticalAlignment = wdAlignVerticalTop
.SuppressEndnotes = True
.MirrorMargins = False
.TwoPagesOnOne = False
.BookFoldPrinting = False
.BookFoldRevPrinting = False
.BookFoldPrintingSheets = 1
.GutterPos = wdGutterPosLeft
End With
Selection.WholeStory
Selection.ClearFormatting
Selection.MoveUp Unit:=wdLine, Count:=1
With ActiveDocument
.UpdateStylesOnOpen = True
.AttachedTemplate = "Normal"
End With
' Nettoyage des sauts de paragraphes et des césures
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
' 1° Remplace les sauts de ligne superflus par des espaces
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "([!\?.\!:^13])(^13)"
.Replacement.Text = "\1 "
.Forward = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
' 2° Élimine tous les espaces en double
Selection.HomeKey Unit:=wdStory
.Text = " {2;}"
.Replacement.Text = " "
.Execute Replace:=wdReplaceAll
End With
With Selection.Find
.Text = "(^013)([a-z])"
.Replacement.Text = " \2"
.Forward = True
.Wrap = wdFindContinue
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = ChrW(946) & "^013"
.Replacement.Text = ChrW(946)
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Elimine les césures, les tirets conditionnels ou insécables
With Selection.Find
.Text = "-^l"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Remplace les sauts de ligne manuels par des espaces
With Selection.Find
.Text = "^l"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^- "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^-"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^~ "
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^~"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Remplace les tirets spéciaux (cadratins, ...) par des tirets simples
With Selection.Find
.Text = "^+"
.Replacement.Text = "-"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^="
.Replacement.Text = "-"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "- "
.Replacement.Text = "-"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Remplace les espaces spéciaux (fines, insécables) par des espaces simples
With Selection.Find
.Text = "^w"
.Replacement.Text = " "
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^w^p"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p^w"
.Replacement.Text = "^p"
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "^s"
.Replacement.Text = " "
.Forward = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
' Nettoyage ponctuation et caractères divers
'
' 1° suppression espace devant certains signes
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "( )([;:\!\?,=\)»])"
.Replacement.Text = "\2"
.Forward = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
' 2° suppression espace après certains signes
With ActiveDocument.Content.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([=\(«])( )"
.Replacement.Text = "\1"
.Forward = True
.MatchWildcards = True
.Execute Replace:=wdReplaceAll
End With
' 3° Gestion des guillemets
Call Guillemet
' 4° Traitement des tirets introductifs (liste, dialogue)
With Selection.Find
.Text = "^p- "
.Replacement.Text = "^p-"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p-"
.Replacement.Text = "^p--"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "^p---"
.Replacement.Text = "^p--"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Dans un nombre, sépare les groupes de 3 chiffres avec le point 3
With Selection.Find
.Text = "([0-9])( )([0-9])"
.Replacement.Text = "\1'\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{3})([0-9]{3})([0-9]{3})"
.Replacement.Text = "\1'\2'\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{2})([0-9]{3})([0-9]{3})"
.Replacement.Text = "\1'\2'\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{1})([0-9]{3})([0-9]{3})"
.Replacement.Text = "\1'\2'\3"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{3})([0-9]{3})"
.Replacement.Text = "\1'\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{2})([0-9]{3})"
.Replacement.Text = "\1'\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "(<[0-9]{1})([0-9]{3})"
.Replacement.Text = "\1'\2"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
'Rétablit la fonction de correction automatique
Options.AutoFormatAsYouTypeReplaceQuotes = True
'Boîte de dialogue permettant d'enregister le fichier 
'en ajoutant BRL à la fin du nom
Call Enr_Fich_Nett
End Sub

Sub Guillemet()
' Macro créée par Franck A en 2015
'------------------------------------------------------------------------
'Cette macro a pour rôle de remplacer
'Tous les guillemets courbes français «» ou anglais “”
'par des guillemets droits "
'Elle peut être intégrée à la macro NettBraille.
'------------------------------------------------------------------------
'
'Désactive la fonction de correction automatique
Options.AutoFormatAsYouTypeReplaceQuotes = False
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
'Gestion des guillemets
With Selection.Find
.Text = "«"
.Replacement.Text = ChrW(34)
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = "»"
.Replacement.Text = ChrW(34)
.Forward = True
.Wrap = wdFindContinue
.MatchWildcards = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
Options.AutoFormatAsYouTypeReplaceQuotes = True
End Sub


Sub Enr_Fich_Nett()
'
' Macro créée par Franck A en 2015
'------------------------------------------------------------------------
'Cette macro a pour simple rôle d'afficher une boîte de dialogue demandant
'si l'on souhaite enregistrer le fichier.
'à améliorer en fusionnant la macro avec Sauv_Fich_Nett
'------------------------------------------------------------------------
'
Dim strMyResponse As Integer
Select Case MsgBox("Voulez-vous enregistrer le fichier" & Chr(10) & "en ajoutant BRL " & Chr(10) & "à votre nom de fichier ?", vbYesNoCancel + vbQuestion + vbDefaultButton1, "Votre choix")
Case vbYes
Call Sauv_Fich_Nett
Case vbNo
MsgBox "Sauvegarde non effectuée", , "Refusé"
Case vbCancel
MsgBox "Opération annulée", , "Annuler"
End Select
End Sub

Sub Sauv_Fich_Nett()
'
' Macro créée par Franck A en 2015
'------------------------------------------------------------------------
'Cette macro permet de choisir le dossier dans lequel sera enregistré le fichier "nettoyé"
'On garde le nom original du fichier en ajoutant BRL à la fin de celui-ci
'Rque: On ne peut pas enregistrer à la racine de C:
'------------------------------------------------------------------------
'
'Déclaration des variables
Dim objShell As Object, objFolder As Object
Dim SecuriteSlash As Integer
Dim Chemin As String
Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.BrowseForFolder(&H0&, "Choisir un répertoire", &H1&)
On Error Resume Next
'Récupère le chemin sélectionné (objFolder.Title renvoie le dossier selectionné)
Chemin = objFolder.ParentFolder.ParseName(objFolder.Title).Path
'Verifie si l'utilisateur a cliqué sur la croix ou le bouton "Annuler"
If objFolder.Title = "" Then Chemin = ""
'Interdit d'écrire à la racine de C:
SecuriteSlash = InStr(objFolder.Title, "C:")
'Récupère le nom du fichier original sans l'extension
Pos = InStr(1, ActiveDocument.Name, ".", 1)
NomFichierSansExtension = Chemin & "\" & Left(ActiveDocument.Name, Pos - 1)
'Vérifie si le nom du fichier se termine déjà par BRL
'Si non sauve le fichier dans le répertoire sélectionné en ajoutant BRL au nom
If Right(NomFichierSansExtension, 3) <> "BRL" Then
ActiveDocument.SaveAs2 FileName:=NomFichierSansExtension & " BRL", FileFormat:=wdFormatXMLDocument
'Si oui sauve le fichier dans le répertoire sélectionné sans changer le nom
Else: ActiveDocument.SaveAs2 FileName:=NomFichierSansExtension, FileFormat:=wdFormatXMLDocument
End If
'Permet de remettre en forme pour obtenir C:
If SecuriteSlash > 0 Then Chemin = Mid(objFolder.Title, SecuriteSlash - 1, 2) & ""
End Sub
Apache Open Office 4.1.2 sous Windows 10 v1511 14342.1001