|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Sub 批量word()
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Dim wdApp As Object
Set wdApp = CreateObject("Word.Application") '新建Word对象
Dim sj001, sj002, sj003
Dim d As Object
Dim wdd
t = Timer
Dim ar As Variant
Dim br()
lj = ThisWorkbook.Path
mb = lj & "\全日制用工劳动合同示范文本.doc"
ar = ActiveSheet.[a1].CurrentRegion
wdApp.Visible = False
For i = 2 To UBound(ar)
If Len(Trim(ar(i, 1))) > 0 Then
wj = ar(i, 1)
ar(i, 10) = ar(i, 1)
FileCopy mb, lj & "\劳动合同\" & wj & ".doc"
Set wdd = wdApp.Documents.Open(lj & "\劳动合同\" & wj & ".doc")
For j = 1 To 10
With wdApp.Selection
.HomeKey unit:=6 '光标置于文件首
If .Find.Execute("数据" & j) Then '查找到指定字符串
.Font.Color = wdColorAutomatic '字符为自动颜色
.Text = ar(i, j) '替换字符串
End If
End With
Next j
With wdApp.Selection
.HomeKey unit:=6 '光标置于文件首
If .Find.Execute("xm") Then '查找到指定字符串
.Font.Color = wdColorAutomatic '字符为自动颜色
.Text = ar(i, 1) '替换字符串
End If
End With
wdd.Save
wdd.Close True
End If
Next i
wdApp.Quit
Set wdd = Nothing
Set wdApp = Nothing
Application.DisplayAlerts = True
Application.ScreenUpdating = True
MsgBox "耗时:" & Format(Timer - t, "0.00") & "秒"
End Sub
|
|