|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
给你段代码,自己研究吧:
Sub test()
Dim myword, thispath, mydoc, r&, i&, j&
Set myword = CreateObject("word.application")
thispath = ThisWorkbook.Path & "\"
r = Sheet1.[b65536].End(3).Row
For i = 2 To r
mydoc = thispath & "授课通知(" & Sheet1.Cells(i, 2) & ").doc"
FileCopy thispath & "授课通知(模板).doc", mydoc
With myword
.documents.Open mydoc
.Visible = True
For j = 1 To 5
If .Selection.Find.Execute("数据" & Format(j, "000")) Then
.Selection.Text = Sheet1.Cells(i, j + 1)
.Selection.MoveRight Unit:=1, Count:=1
End If
Next j
For j = 1 To 3
.activedocument.tables(1).cell(2, j) = Sheet1.Cells(i, j + 6)
.activedocument.tables(1).cell(4, j) = Sheet1.Cells(i, j + 9)
Next j
'--------------------------------------------
.ActiveWindow.ActivePane.View.SeekView = 9
If .Selection.Find.Execute("数据006") Then
.Selection.Text = "中心小学"
End If
.ActiveWindow.ActivePane.View.SeekView = 10
If .Selection.Find.Execute("数据007") Then
.Selection.Text = "宁阳县"
End If
'------------------------------------------
.documents.Close True
End With
Next i
myword.Quit
End Sub |
|