|
楼主 |
发表于 2022-8-29 11:51
|
显示全部楼层
Public Sub 进货台账()
Dim i%, r%
Dim wdDoc As Word.Document
Dim mWord As New Word.Application
Application.ScreenUpdating = False
Set d = CreateObject("scripting.dictionary")
With Worksheets("今日供货清单")
r = Range("A1").End(xlToRight).Column
arr = .Range("a2:d" & r)
For i = 1 To UBound(arr)
If Not d.Exists(arr(i, 1)) Then
Set d(arr(i, 1)) = CreateObject("scripting.dictionary")
End If
d(arr(i, 1))(arr(i, 3)) = Empty
Next
End With
Set wdDoc = mWord.Documents.Open(ThisWorkbook.Path & "\今日清单模板.docx")
For Each aa In d.keys
With wdDoc
With .Tables(1)
.Cell(1, 2).Range.Text = aa
.Cell(4, 3).Range.Text = Join(d(aa).keys, ",")
End With
.SaveAs2 "D:\" & Replace(Range("A" & i), "/", "-") & ".docx"
End With
Next
wdDoc.Close False
mWord.Quit
Application.ScreenUpdating = True
End Sub
请高手指点, r = Range("A1").End(xlToRight).Column 这一句导致导出结果只有最后一个有效值, 加上 r = Range("A1").End(xlDown).Row 导出来的文件可以增加第一个有效值。
|
|