Bonjour a tous,
Je cherche a faire la même chose que la macro qui suit (et qui marche très bien), mais a partir d'une macro Word et non Excel car mon fichier excel change toutes les semaines.
Public Sub test()
Dim WordApp As Word.Application
Dim WordDoc As Word.Document
Dim i As Byte
Dim n As Long
Set WordApp = CreateObject("word.application") 'ouvre une session Word
Set WordDoc = WordApp.Documents.Open("monfichier.doc") 'ouvre le document Word
WordApp.Visible = False 'Word est masqué pendant l'opération
n = Range("A2").SpecialCells(xlCellTypeLastCell).Row 'Compte le nombre de lignes non vides
For i = 2 To n
If Cells(i, 5) = "A" Then
'les signets du document Word sont nommés Signet1 , Signet2 , Signet3 ,...
WordDoc.Bookmarks("Signet" & 1).Range.Text = Cells(i, 16) & vbCrLf
ElseIf Cells(i, 5) = "B" Then
WordDoc.Bookmarks("Signet" & 2).Range.Text = Cells(i, 16) & vbCrLf
ElseIf Cells(i, 5) = "C" Then
WordDoc.Bookmarks("Signet" & 3).Range.Text = Cells(i, 16) & vbCrLf
ElseIf Cells(i, 5) = "D" Then
WordDoc.Bookmarks("Signet" & 4).Range.Text = Cells(i, 16) & vbCrLf
ElseIf Cells(i, 5) = "E" Then
WordDoc.Bookmarks("Signet" & 5).Range.Text = Cells(i, 16) & vbCrLf
End If
Next i
WordApp.Visible = True 'affiche le document Word
End Sub
Voila ce que j'ai commencé a faire :
Public Sub test1()
Dim ExcelApp As Excel.Application
Dim ExcelDoc As Excel.Workbook
Dim i As Byte
Dim n As Long
Set ExcelApp = CreateObject("excel.application") 'ouvre une session Excel
Set ExcelDoc = ExcelApp.Workbooks.Open("fichierexcel.xlsm") 'ouvre le document Excel
ExcelApp.Visible = False 'Excel est masqué pendant l'opération
Je n'arrive pas a continuer... Sauriez-vous m'aider ?
Bonne journee