bonjour,
j'ai crée une macro ou :
1) je saisis le chemin du repertoire ou il y a plein des fichiers *.doc
2) et je parcours le repertoire et les fichiers et je mets le nom des fichiers dans excel (boucle)
jusqu'ici tout ce passe bien
3) en suite je dois ouvrir le fichier word en cours (boucle 2) ) et recupere le nbpage du doc puis le fermer
et la j'ai un erreur du type
voici le code de ma macro ( macro excel ) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 user-defined type not defined
donc voici l'endroit ou il y a l'erreur :
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 '======================================================' '= the user paste the paste of folder and push button =' '= the macro find doc file in the folder =' '= each name of file is listed in excel sheet =' '= =' '======================================================' Option Explicit Public folderinput As String Public rep As String Public nbpage As Integer Public Sub btnlist_Click() Dim celex As String Dim i As Integer folderinput = txtfolder.Value Debug.Print folderinput i = 1 'path folder to parse rep = Dir(folderinput & "\*.doc", vbDirectory) 'loop while not end of folder et <>empty Do While (rep <> "") If (GetAttr(folderinput & "\" & rep)) <> vbDirectory Then Debug.Print rep celex = Left(Right(rep, 14), 10) Debug.Print celex If IsNumeric(Left(celex, 5)) Then Cells(i, 1).Value = celex Call OpenDocument Cells(i, 2).Value = nbpage i = i + 1 End If End If 'next file rep = Dir Loop MsgBox ("There is/are " & i & " files ") End Sub Sub OpenDocument() Dim appwd As Word.Application Dim wordfile As String wordfile = folderinput & "\" & rep Debug.Print wordfile Set appwd = CreateObject("Word.Application") With appwd .WordBasic.DisableAutoMacros 1 '0 pour activer .Visible = True .Documents.Open wordfile .Activate End With nbpage = ActiveDocument.Range.Information(wdActiveEndPageNumber) Debug.Print nbpage appwd.Documents.Close End Sub
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8 Call OpenDocument puis ici : Dim appwd As Word.Application
je ne sais pas pourquoi il y a une erreur , j'ai regardé dans la faq
si une âme charitable pouvait m'aider
merci![]()
Partager