Lancer une macro Excel depuis word
K
bonjour j'essaye de lancer une macro excel depuis word le fichier souvre bien les donner sont bien copier mais la macro ne ce lance pas .. je trouve pas pourquoi
Sub effectif()
Dim a As String, b As String, c As String, d As String, e As String, f As String, g As String, h As String, i As String, j As String, k As String, Chemin As String
Dim Doc As Document
Dim XlApp As Excel.Application ' Référencer Microsoft Excel
Dim FichierExcel As Excel.Workbook
Set Doc = ActiveDocument
On Error Resume Next
With Doc
a = .Tables(1).Cell(1, 2).Range.Text
b = .Tables(1).Cell(1, 4).Range.Text
c = .Tables(1).Cell(2, 2).Range.Text
'd = .Tables(1).Cell(2, 4).Range.Text
e = .Tables(2).Cell(5, 2).Range.Text
f = .Tables(2).Cell(7, 2).Range.Text
g = .Tables(2).Cell(3, 2).Range.Text
h = .Tables(2).Cell(18, 2).Range.Text
i = .Tables(2).Cell(19, 2).Range.Text
j = .Tables(2).Cell(24, 2).Range.Text
k = .Tables(2).Cell(1, 2).Range.Text
End With
Set XlApp = CreateObject("Excel.Application")
Chemin = chemineffectif ' A adapter
With XlApp
.Visible = True ' Pendant la phase développement.
Set FichierExcel = .Workbooks.Open(FileName:=Chemin, Password:=psw)
With FichierExcel
.Sheets(1).Range("B9").Value = Mid(a, 1, Len(a) - 1)
.Sheets(1).Range("B10").Value = Mid(b, 1, Len(b) - 1)
.Sheets(1).Range("B12").Value = Mid(c, 1, Len(c) - 1)
.Sheets(1).Range("B13").Value = Mid(k, 1, Len(k) - 1)
.Sheets(1).Range("B20").Value = Mid(e, 1, Len(e) - 1)
.Sheets(1).Range("B14").Value = Mid(f, 1, Len(f) - 1)
.Sheets(1).Range("B16").Value = Mid(g, 1, Len(g) - 1)
.Sheets(1).Range("B17").Value = Mid(h, 1, Len(h) - 1)
.Sheets(1).Range("B15").Value = Mid(i, 1, Len(i) - 1)
.Sheets(1).Range("B18").Value = Mid(j, 1, Len(j) - 1)
'Debug.Print .sheets(1).Range("B40")
'.Close savechanges:=True
With Doc
If .Tables(2).Cell(4, 2).Range.Text = "Pouponnière Unité 1" Then
XlApp.Sheets(1).Range("B21").Value = "Unité 1"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Pouponnière Unité 2" Then
XlApp.Sheets(1).Range("B21").Value = "Unité 2"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Pouponnière Unité 3" Then
XlApp.Sheets(1).Range("B21").Value = "Unité 3"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Les Mousses" Then
XlApp.Sheets(1).Range("B21").Value = "Les Mousses"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "7/11 ans" Then
XlApp.Sheets(1).Range("B21").Value = "7 11 ans"
XlApp.Run ("ajouterauto")
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Etampes" Then
XlApp.Sheets(1).Range("B21").Value = "Etampes"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Orsay" Then
XlApp.Sheets(1).Range("B21").Value = "Orsay"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Adoles'sens" Then
XlApp.Sheets(1).Range("B21").Value = "Unité 1"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "Horizon" Then
XlApp.Sheets(1).Range("B21").Value = "Horizon"
XlApp.Run "ajouterauto"
xlBook.Save
Else
If .Tables(2).Cell(4, 2).Range.Text = "PFAU" Then
XlApp.Sheets(1).Range("B21").Value = "PFAU"
XlApp.Run "ajouterauto"
xlBook.Save
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
End With
End With
End With
XlApp.Close savechanges:=True
XlApp.Quit
GoTo Fin
Fin:
Set FichierExcel = Nothing
Set XlApp = Nothing
Set Doc = Nothing
End Sub
21FormaticPassionné d'Excel
- Messages
- 3'581
- Excel
- 2013, 2019, 365
- Inscrit
- 11/04/2020
- Emploi
- Formateur bureautique, dvpt fichiers
Bonjour,
Quand on lance une macro Word depuis Excel, il faut également spécifier le module dans lequel se trouve la macro.
Peut-être est-ce le cas ici aussi ?
K
Bonjour j'ai essayer mais peu etre mal ecris la macro ce trouve dans le module2
j'avais essayer
XlApp.Run "module2!ajouterauto"
mais ça na pas marcher ^^" peu etre erreur de ma part en tous cas merci de votre reponse