|
- Sub test1()
- iweizhi = 14
- '生成合同文件
- Dim yangbenpath As String
- yangbenpath = Application.ActiveWorkbook.Path & Sheets("明细").Cells(iweizhi, 23).Value '获取修改文件《测试.doc》的位置
- Dim deskpath As String
- Dim weizhi As Variant
- Dim WdApp, Wd
- Application.ScreenUpdating = False
- Set WdApp = CreateObject("word.application")
- Set Wd = WdApp.Documents.Open(yangbenpath) '打开文件《测试.doc》
- WdApp.Visible = True
- WdApp.Selection.Find.ClearFormatting
- 'weizhi = Split(Sheets("明细").Cells(iweizhi, 24).Value, ",") '以,号分隔的数据赋值
- Dim i As Long
- 'For i = 0 To UBound(weizhi)
- For i = 23 To 32 Step 1
- '替换cells(23,23)到cells(32,24)里面对应的内容
- WdApp.Selection.Find.Replacement.ClearFormatting
- With WdApp.Selection.Find
- .ClearFormatting
- .Text = Sheets("明细").Cells(i, 23).Value
- .Replacement.ClearFormatting
- .Replacement.Text = Sheets("明细").Cells(i, 24).Value
- .Execute Replace:=wdReplaceAll, Forward:=True, Wrap:=wdFindContinue
- End With
- Next i
- deskpath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & "" '获取桌面位置路径
- Wd.SaveAs deskpath & Sheets("明细").Cells(3, 24).Value & ".doc" '另存到桌面,文件名称为合同名
- WdApp.Visible = True
- Set Wd = Nothing
- Set WdApp = Nothing
- Application.ScreenUpdating = True
- End Sub
复制代码 |
|