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
| Private Sub Document_Open()
Dim oDoc As Document
Dim oTbl As Table
Dim xlApp As New Excel.Application
Dim xlWB As Excel.Workbook
Dim xlSH As Excel.Worksheet
Dim iR As Integer
Dim i As Integer
iR = 0
Set xlWB = xlApp.workbooks.Open("c:\temp\a.xls")
Set xlSH = xlWB.Worksheets(1)
iR = xlSH.Range("A3").End(xlDown).Row
Debug.Print iR
For i = 3 To iR
Set oDoc = Documents.Add("c:\temp\publipostage.dot")
Set oTbl = oDoc.Tables(1)
With oDoc
.Bookmarks("S1").Range.Text = xlSH.Cells(i, 1)
.Bookmarks("S2").Range.Text = xlSH.Cells(i, 3) & vbCrLf & xlSH.Cells(i, 4)
End With
With oTbl
.Cell(1, 1).Range.Text = xlSH.Cells(i, 6)
.Cell(1, 2).Range.Text = xlSH.Cells(i, 7)
.Cell(1, 3).Range.Text = xlSH.Cells(i, 8)
End With
oDoc.SaveAs "c:\Temp\" & xlSH.Cells(i, 1) & ".doc"
oDoc.Close
Set oDoc = Nothing
Next i
xlWB.Close
Set xlWB = Nothing
Set xlApp = Nothing
End Sub |
Partager