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
| Function creerElementRepertoire()
'déclaration des variables
Dim k As Integer
Dim i As Integer
Dim base As String
Dim nom As String
Dim nomFichier As String
Dim sheetParametres As String
'Affectation des vriables
sheetParametres = "Parametres"
k = Application.WorksheetFunction.CountA(Sheets(sheetParametres).Range("A2:A65000"))
base = "C:\VBA_Creation\"
For i = 2 To k + 1
nomFichier = base & ActiveWorkbook.Sheets(sheetParametres).Range("A" & i).Value & "\" & ActiveWorkbook.Sheets(sheetParametres).Range("A" & i).Value & ".Doc"
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Set WordApp = CreateObject("Word.Application") '-- ouvre une session Word
WordApp.Visible = False
Set WordDoc = WordApp.Documents.Add '-- crée un nouveau document
WordDoc.SaveAs nomFichier '-- enregistre le nouveau doc
WordDoc.Close
Next i
End Function |