|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
下面是我自己弄的代码,新手一枚,参考别的代码修改的,现在的问题是word页眉里的公司名称替换不掉,有没有大神给加一段代码能修改页眉里的文字
Sub 替换()
Dim n As String, b As String, z As String, s As String, q As String, baogao, mypath, c, i
n = Range("B2").Text
b = Range("C2").Text
z = Range("F2").Text
s = Range("G2").Text
q = Range("D2").Text
mypath = ThisWorkbook.Path & "\"
c = Array("15报告", "16报告", "17报告", "收入报告", "费用报告")
For Each i In c
Set baogao = CreateObject("word.application")
With baogao
.Visible = False
.documents.Open mypath & i
Do While .Selection.Find.Execute("这里是公司名称")
.Selection.Text = n
.Selection.homekey unit:=6
Loop
Do While .Selection.Find.Execute("这里是编号")
.Selection.Text = b
.Selection.homekey unit:=6
Loop
Do While .Selection.Find.Execute("这里是企业会计制度")
.Selection.Text = z
.Selection.homekey unit:=6
Loop
Do While .Selection.Find.Execute("这里是出报告日期")
.Selection.Text = s
.Selection.homekey unit:=6
Loop
.documents.Save
.Quit
End With
Next i
Set baogao = Nothing
End Sub
|
|