Précédent   Forum des professionnels en informatique > Logiciels > Microsoft Office > Word > VBA Word
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 07/11/2007, 16h15   #1
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Par défaut ouvrir un fichier .txt dans word en le passant en codage europe occidentale

Bonjour,

j'aimerais automatiser la conversion de fichiers textes (*.txt) dans word, leur appliquer une macro et les sauver, le tout en VBS.

j'ai un début de script mais il importe le fichier tel qu'il est et ne change pas le codage en europe occidentale (DOS)...

Code :
1
2
3
4
5
6
7
8
9
10
Dim WordApp 'As Word.Application
Dim WordDoc 'As Word.Document
 
Set WordApp = CreateObject("Word.Application") '-- ouvre une session Word
WordApp.Visible = True
Set WordDoc = WordApp.Documents.Open("J:\fichier1.TXT") '-- crée un nouveau document
 
'WordApp.Run "laMacro"
 
'WordDoc.SaveAs "C:\monDocument.doc" '-- enregistre le nouveau doc

Merci d'avance pour votre aide...!

A Bientôt
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 07/11/2007, 17h50   #2
Responsable Word

 
Avatar de Heureux-oli
 
Homme Olivier Lebeau
Contrôleur d'industrie
Inscription : février 2006
Messages : 17 354
Détails du profil
Informations personnelles :
Nom : Homme Olivier Lebeau
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Contrôleur d'industrie
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2006
Messages : 17 354
Points : 29 270
Points : 29 270
tu ne dois pas le faire en VBS, mais en VBA qui permet l'utilisation de paramètres plus performants.
__________________
J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
Débutez en VBA

Mes articles


Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !
Heureux-oli est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2007, 08h43   #3
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Merci pour votre réponse.

Pouvez vous me montrer comment faire en VBA?

Cordialement
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2007, 09h20   #4
Responsable Word

 
Avatar de Heureux-oli
 
Homme Olivier Lebeau
Contrôleur d'industrie
Inscription : février 2006
Messages : 17 354
Détails du profil
Informations personnelles :
Nom : Homme Olivier Lebeau
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Contrôleur d'industrie
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2006
Messages : 17 354
Points : 29 270
Points : 29 270
Aurais-tu un exemple de fichier ?
__________________
J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
Débutez en VBA

Mes articles


Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !
Heureux-oli est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2007, 09h49   #5
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Je vous ai posté un exemple sur votre mail.

Cordialement
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 08/11/2007, 14h19   #6
Responsable Word

 
Avatar de Heureux-oli
 
Homme Olivier Lebeau
Contrôleur d'industrie
Inscription : février 2006
Messages : 17 354
Détails du profil
Informations personnelles :
Nom : Homme Olivier Lebeau
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Contrôleur d'industrie
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2006
Messages : 17 354
Points : 29 270
Points : 29 270
Une première piste

Code :
1
2
3
4
5
6
7
8
 
Sub OpenFichier()
Dim fil As String
 
fil = "F:\Documents and Settings\Olivier\Mes documents\Word\Forum\sample.txt"
Application.Documents.Open fileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
 
End Sub
__________________
J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
Débutez en VBA

Mes articles


Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !
Heureux-oli est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2007, 08h45   #7
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Merci, je vais tenter de l'appliquer.

je débute en VBA et j'aimerais savoir si il est possible de vérifier si tel ou tel fichier existe avant de lancer cette ligne de commande?

je m'explique, je voudrais vérifier que les fichier sample1.txt, sample2.txt, sample3.txt etc sont bien présent pour ne pas qu'il y ai de message d'erreur. et au cas ou un fichier n'est pas present ne pas lancer la ligne qui va aller ouvrir le fichier et lancer la macro bien sur...

merci d'avance

Maverick
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2007, 08h51   #8
Responsable Word

 
Avatar de Heureux-oli
 
Homme Olivier Lebeau
Contrôleur d'industrie
Inscription : février 2006
Messages : 17 354
Détails du profil
Informations personnelles :
Nom : Homme Olivier Lebeau
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Contrôleur d'industrie
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2006
Messages : 17 354
Points : 29 270
Points : 29 270
Oui,

Voici un lien vers un peu de lecture.

Je pense que le réponse s'y trouve.
Et un lien en plus ici
__________________
J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
Débutez en VBA

Mes articles


Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !
Heureux-oli est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2007, 09h05   #9
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Wow! Merci pour votre reponse si rapide!
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 09/11/2007, 14h29   #10
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Merci de m'avoir dépanné, j'ai pu réaliser mon programme grâce à vos conseils.

Cordialement
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2007, 12h01   #11
Invité de passage
 
Inscription : novembre 2007
Messages : 13
Détails du profil
Informations forums :
Inscription : novembre 2007
Messages : 13
Points : 2
Points : 2
Par défaut Probleme dans ma macro...

Bonjour,

ma macro n'as plus l'air de vouloir fonctionner et j'avoue que je ne voit pas pourquoi...les fichiers txt à transformer en doc sont respectivement
verif.01.bon.txt
verif.02.bon.txt
verif.61.bon.txt
verif.71.bon.txt
or word ouvre les 2 premiers puis s'arrete là comme si il n'arrivait pas à sauter les fichiers qu'il ne trouve pas...

voici le code
Code :
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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
Sub CABLAGE_ARMOIRE()
 
Dim fil As String
 
Set fs = CreateObject("Scripting.FileSystemObject")
If fs.FileExists("J:\COMMON\TEMP\VERIF.01.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.01.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
End If
If fs.FileExists("J:\COMMON\TEMP\VERIF.02.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.02.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.03.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.03.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.04.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.04.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.05.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.05.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.06.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.06.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.11.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.11.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.12.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.12.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.21.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.21.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.22.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.22.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.61.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.61.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.62.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.62.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.71.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.71.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.72.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.72.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.80.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.80.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.81.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.81.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.90.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.90.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.91.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.91.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
If fs.FileExists("J:\COMMON\TEMP\VERIF.92.BON.TXT") Then
   fil = "J:\COMMON\TEMP\VERIF.92.BON.TXT"
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End Sub
J'ai essayé de mettre des goto, etc mais ça ne change pas le probleme...

please help!
maverick5976 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 15/11/2007, 12h14   #12
Responsable Word

 
Avatar de Heureux-oli
 
Homme Olivier Lebeau
Contrôleur d'industrie
Inscription : février 2006
Messages : 17 354
Détails du profil
Informations personnelles :
Nom : Homme Olivier Lebeau
Âge : 47
Localisation : Belgique

Informations professionnelles :
Activité : Contrôleur d'industrie
Secteur : Aéronautique - Marine - Espace - Armement

Informations forums :
Inscription : février 2006
Messages : 17 354
Points : 29 270
Points : 29 270
Perso, je n'aurais pas fais comme ça, j'aurais fais une boucle et l'appel d'une fonction.

Code :
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
 
Public Function Convert( fil as string)
Application.Documents.Open FileName:=fil, Format:=wdOpenFormatAuto, Encoding:=850
    Selection.WholeStory
    Selection.Font.Size = 8
    With ActiveDocument.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(1.75)
        .BottomMargin = CentimetersToPoints(2.53)
        .LeftMargin = CentimetersToPoints(2.03)
        .RightMargin = CentimetersToPoints(2.03)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(21)
        .PageHeight = CentimetersToPoints(29.7)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .GutterPos = wdGutterPosLeft
    End With
End Function
La fonction n'est pas correcte, c'est juste un exemple.

L'appel de la fonction :
Code :
1
2
3
4
5
 
Public Sub ChercherFichier()
If fs.FileExists("J:\COMMON\TEMP\VERIF.03.BON.TXT") Then
   Convert( "J:\COMMON\TEMP\VERIF.03.BON.TXT")
End Sub
Pour la recherche des fichier, il y a une source intéressante
Ici
Elle va te simplifier la vie.
Le code permet d'aller chercher les fichiers d'un répertoire, il suffit alors de faire une boucle.
__________________
J'ai pas encore de décodeur, alors, postez en clair ! Comment mettre une balise de code ?
Débutez en VBA

Mes articles


Dans un MP, vous pouvez me dire que je suis beau, ... mais si c'est une question technique je ne la lis pas ! Vous êtes prévenus !
Heureux-oli est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 10h33.


 
 
 
 
Partenaires

Hébergement Web