|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_Click()
Set d = CreateObject("scripting.dictionary")
crr = Array(2, 3, 5, 12)
Application.ScreenUpdating = False
Set wordApp = CreateObject("Word.Application")
wordApp.Visible = True
arr = ActiveSheet.UsedRange
For j = 4 To UBound(arr)
If Len(arr(j, 2)) > 0 Then
d(arr(j, 2)) = d(arr(j, 2)) & "#" & j
End If
Next j
For Each k In d.keys
Set doc = wordApp.Documents.Open(ThisWorkbook.Path & "\销售合同样本.docx")
brr = Split(d(k), "#")
For j = 2 To 12
For i = 1 To 6
doc.tables(1).cell(j, i) = ""
Next i
Next j
For j = 1 To UBound(brr)
r = Val(brr(j))
For i = 6 To 10
doc.tables(1).cell(j + 1, i - 5) = arr(r, i)
Next i
Next j
For Each x In crr
With doc.Content.Find
.Text = "【" & x & "】"
.Replacement.Text = arr(Val(brr(1)), x)
.Execute Replace:=2
End With
Next x
doc.tables(1).cell(13, 5) = arr(Val(brr(1)), 11)
doc.SaveAs ThisWorkbook.Path & "\" & arr(Val(brr(1)), 2) & "-" & arr(Val(brr(1)), 3) & ".docx"
doc.Close
Next k
Application.ScreenUpdating = True
End Sub
|
|