Bonjour, J'ai une macro dans Visual Basic que je souhaite passer dans un projet Visual Basic de Visual Studio.
Lorsque je créer mon projet et que j'ajoute les mêmes références, j'ai encore des erreurs de recompile.

Comment dois-je faire ?

Merci !

Ma macro dans Visual Basic à passer dans Visual studio :
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
 
Sub GenereMacros()
'
' GenereMacros Macro
' Macro créée le 16/10/2008 par acer
'
Dim Fichier As String, Direction As String
 
' -------------- REPERTOIRE DES FICHIERS WORD ------------------------
Direction = "C:\FichiersWord"
' --------------------------------------------------------------------
 
Dim Debut As Integer, Lignes As Integer, X As Integer
Dim Doc As Document
Dim NewModule As VBIDE.VBComponent
 
Application.ScreenUpdating = False
 
' Fichier .dot
Fichier = Dir(Direction & "\*.dot")
Do While Fichier <> ""
    Set Doc = Documents.Open(Direction & "\" & Fichier)
    Set NewModule = Doc.VBProject.VBComponents _
                    .Add(vbext_ct_StdModule)
    NewModule.Name = "MyModule"
 
    With Doc.VBProject.VBComponents("MyModule").CodeModule
    X = .CountOfLines
    .InsertLines X + 1, "Sub AutoOpen()"
    .InsertLines X + 2, "' AutoOpen Macro"
    .InsertLines X + 3, "' Macro created 05/10/2008 by acer"
    .InsertLines X + 4, "Dim aStory As Range"
    .InsertLines X + 5, "Dim aField As Field"
    .InsertLines X + 6, "Dim tableau(1000) As String"
    .InsertLines X + 7, "Dim i As Integer"
    .InsertLines X + 8, "Dim majOK As Boolean"
    .InsertLines X + 9, "Dim cptTableau As Integer"
    .InsertLines X + 10, "cptTableau = 0"
    .InsertLines X + 11, "For Each aStory In ActiveDocument.StoryRanges"
    .InsertLines X + 12, "For Each aField In aStory.Fields"
    .InsertLines X + 13, "majOK = True"
    .InsertLines X + 14, "For i = 0 To cptTableau"
    .InsertLines X + 15, "If UCase(tableau(i)) = UCase(aField.Code.Text) Then"
    .InsertLines X + 16, "majOK = False"
    .InsertLines X + 17, "End If"
    .InsertLines X + 18, "Next i"
    .InsertLines X + 19, "If majOK = True Then"
    .InsertLines X + 20, "aField.Update"
    .InsertLines X + 21, "If InStr(aField.Code.Text, ""ASK"") <> 0 Then"
    .InsertLines X + 22, "tableau(cptTableau) = aField.Code.Text"
    .InsertLines X + 23, "cptTableau = cptTableau + 1"
    .InsertLines X + 24, "End If"
    .InsertLines X + 25, "End If"
    .InsertLines X + 26, "Next aField"
    .InsertLines X + 27, "Next aStory"
    .InsertLines X + 28, "ActiveWindow.Activate"
    .InsertLines X + 29, "ActiveWindow.WindowState = wdWindowStateMaximize"
    .InsertLines X + 30, "If (ActiveWindow.View.ShowFieldCodes) Then"
    .InsertLines X + 31, "ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes"
    .InsertLines X + 32, "End If"
    .InsertLines X + 33, "End Sub"
    End With
DoEvents
Doc.Close True
Set Doc = Nothing
Fichier = Dir
Loop
 
' Fichier .doc
Fichier = Dir(Direction & "\*.doc")
Do While Fichier <> ""
    Set Doc = Documents.Open(Direction & "\" & Fichier)
    Set NewModule = Doc.VBProject.VBComponents _
                    .Add(vbext_ct_StdModule)
    NewModule.Name = "MyModule"
 
    With Doc.VBProject.VBComponents("MyModule").CodeModule
    X = .CountOfLines
    .InsertLines X + 1, "Sub AutoOpen()"
    .InsertLines X + 2, "' AutoOpen Macro"
    .InsertLines X + 3, "' Macro created 05/10/2008 by acer"
    .InsertLines X + 4, "Dim aStory As Range"
    .InsertLines X + 5, "Dim aField As Field"
    .InsertLines X + 6, "Dim tableau(1000) As String"
    .InsertLines X + 7, "Dim i As Integer"
    .InsertLines X + 8, "Dim majOK As Boolean"
    .InsertLines X + 9, "Dim cptTableau As Integer"
    .InsertLines X + 10, "cptTableau = 0"
    .InsertLines X + 11, "For Each aStory In ActiveDocument.StoryRanges"
    .InsertLines X + 12, "For Each aField In aStory.Fields"
    .InsertLines X + 13, "majOK = True"
    .InsertLines X + 14, "For i = 0 To cptTableau"
    .InsertLines X + 15, "If UCase(tableau(i)) = UCase(aField.Code.Text) Then"
    .InsertLines X + 16, "majOK = False"
    .InsertLines X + 17, "End If"
    .InsertLines X + 18, "Next i"
    .InsertLines X + 19, "If majOK = True Then"
    .InsertLines X + 20, "aField.Update"
    .InsertLines X + 21, "If InStr(aField.Code.Text, ""ASK"") <> 0 Then"
    .InsertLines X + 22, "tableau(cptTableau) = aField.Code.Text"
    .InsertLines X + 23, "cptTableau = cptTableau + 1"
    .InsertLines X + 24, "End If"
    .InsertLines X + 25, "End If"
    .InsertLines X + 26, "Next aField"
    .InsertLines X + 27, "Next aStory"
    .InsertLines X + 28, "ActiveWindow.Activate"
    .InsertLines X + 29, "ActiveWindow.WindowState = wdWindowStateMaximize"
    .InsertLines X + 30, "If (ActiveWindow.View.ShowFieldCodes) Then"
    .InsertLines X + 31, "ActiveWindow.View.ShowFieldCodes = Not ActiveWindow.View.ShowFieldCodes"
    .InsertLines X + 32, "End If"
    .InsertLines X + 33, "End Sub"
    End With
DoEvents
Doc.Close True
Set Doc = Nothing
Fichier = Dir
Loop
Application.ScreenUpdating = True
End Sub