根据Excel的内容和word模板生成对应的word文档
Sub setname()
Dim I As Integer
Dim pspname As String
Dim pspnumber As String
Dim path As String
Dim srcPath As String
Dim srcPath2 As String Dim wordApp As Object
Dim wordDoc As Object
Dim wordArange As Object
Dim wordSelection As Object
Dim ReplaceSign As Boolean Dim Search1 As String
Dim Search2 As String
Dim docPrefix As String
Dim docSuffix As String
Dim rangSize As Integer 'docPrefix = "-PSP"
'docSuffix = "采购规格书.doc"
'Search1 = "电线"
'Search2 = "6000397-PSP"
'rangSize = 200 docPrefix = "-TST"
docSuffix = "入厂检验规格书.doc"
Search1 = "高压电源"
Search2 = "6000391-TST"
rangSize = 1100 For I = To
srcPath = "C:\cygwin\tmp\BOM\tst.doc"
path = "D:\bom\" & ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, )
srcPath2 = path & "\aa.doc"
pspname = path & "\" & ActiveSheet.Cells(I, ) & docPrefix & " " & ActiveSheet.Cells(I, ) & docSuffix
pspnumber = ActiveSheet.Cells(I, ) & docPrefix
MkDir (path)
FileCopy srcPath, srcPath2
Name srcPath2 As pspname Set wordApp = CreateObject("Word.Application") '建立WORD实例
wordApp.Visible = False '屏蔽WORD实例窗体
Set wordDoc = wordApp.Documents.Open(pspname) '打开文件并赋予文件实例
Set wordSelection = wordApp.Selection '定位文件实例
Set wordArange = wordApp.ActiveDocument.Range(, rangSize) '指定文件编辑位置
wordArange.Select '激活编辑位置 Do
ReplaceSign = wordArange.Find.Execute(Search1, True, , , , , wdReplaceAll, wdFindContinue, , ActiveSheet.Cells(I, ), True)
Loop Until ReplaceSign = False Dim rngStory As Object
Dim lngJunk As Long
For Each rngStory In wordDoc.StoryRanges
Do
ReplaceSign = rngStory.Find.Execute(Search2, True, , , , , wdReplaceAll, wdFindContinue, , pspnumber, True)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next wordDoc.Save
wordDoc.Close True
wordApp.Quit
Next I
End Sub
Sub setname()
Dim I As Integer
Dim pspname As String
Dim pspnumber As String
Dim path As String
Dim srcPath As String
Dim srcPath2 As String Dim wordApp As Object
Dim wordDoc As Object
Dim wordArange As Object
Dim wordSelection As Object
Dim ReplaceSign As Boolean Dim Search1 As String
Dim Search2 As String
Dim docPrefix As String
Dim docSuffix As String
Dim rangSize As Integer 'docPrefix = "-PSP"
'docSuffix = "采购规格书.doc"
'Search1 = "电线"
'Search2 = "6000397-PSP"
'rangSize = 200 docPrefix = "-TST"
docSuffix = "-V1.0.doc"
Search1 = "高压电源"
Search2 = "6000393-TST"
rangSize = For I = To
srcPath = "C:\cygwin\tmp\BOM\tst14.doc"
path = "D:\bom\" & ActiveSheet.Cells(I, ) & "-" & ActiveSheet.Cells(I, )
srcPath2 = path & "\aa.doc"
'pspname = path & "\" & ActiveSheet.Cells(I, 3) & docPrefix & " " & ActiveSheet.Cells(I, 4) & docSuffix
pspname = path & "\" & ActiveSheet.Cells(I, ) & docPrefix & docSuffix
pspnumber = ActiveSheet.Cells(I, ) & docPrefix
MkDir (path)
FileCopy srcPath, srcPath2
Name srcPath2 As pspname Set wordApp = CreateObject("Word.Application") '建立WORD实例
wordApp.Visible = False '屏蔽WORD实例窗体
Set wordDoc = wordApp.Documents.Open(pspname) '打开文件并赋予文件实例
'Set wordSelection = wordApp.Selection '定位文件实例
'Set wordArange = wordApp.ActiveDocument.Range(0, rangSize) '指定文件编辑位置
'wordArange.Select '激活编辑位置 'Do
' ReplaceSign = wordArange.Find.Execute(Search1, True, , , , , wdReplaceAll, wdFindContinue, , ActiveSheet.Cells(I, 4), True)
'Loop Until ReplaceSign = False Dim rngStory As Object
Dim lngJunk As Long
For Each rngStory In wordDoc.StoryRanges
Do
ReplaceSign = rngStory.Find.Execute(Search2, True, , , , , wdReplaceAll, wdFindContinue, , pspnumber, True)
Set rngStory = rngStory.NextStoryRange
Loop Until rngStory Is Nothing
Next wordDoc.Save
wordDoc.Close True
wordApp.Quit
Next I
End Sub
根据Excel的内容和word模板生成对应的word文档的更多相关文章
- php根据word模板生成新的word文件
原文地址:http://www.niu12.com/article/16 php使用phpword将word内容变量替换 a.安装phpword composer require phpoffice/ ...
- Easypoi实现单模板生成多页wrod文档
EasyPoi可以很方便的通过一个word模板,然后通过填充模板的方式生成我们想要的word文档.但是碰到了一个单模板生成多页数据的场景,比如一个订单详情信息模板,但是有很多订单,需要导入到一 ...
- 使用java Apache poi 根据word模板生成word报表
项目开发过程中,客户提出一堆导出报表的需求,需要导出word格式,页眉还需要加上客户公司的logo,试了几种方案,最后选择了用 Apache poi 加上自定义标签的方式实现. 目前功能还比较简单,一 ...
- 使用word模板生成pdf文件
使用word模板生成pdf文件 源码:UserWord
- SpringBoot集成文件 - 如何基于POI-tl和word模板导出庞大的Word文件?
前文我们介绍了通过Apache POI通过来导出word的例子:那如果是word模板方式,有没有开源库通过模板方式导出word呢?poi-tl是一个基于Apache POI的Word模板引擎,也是一个 ...
- 使用apidoc 生成Restful web Api文档
在项目开发过程中,总会牵扯到接口文档的设计与编写,之前使用的都是office工具,写一个文档,总也是不够漂亮和直观.好在git上的开源大神提供了生成文档的工具,so来介绍一下! 该工具是Nodejs的 ...
- 基于数据库的自动化生成工具,自动生成JavaBean、数据库文档、框架代码等(v5.8.8版)
TableGo v5.8.8版震撼发布,此次版本更新如下: 1.新增两个扩展字段,用于生成自定义模板时使用. 2.自定义模板新增模板目录,可以选择不同分类目录下的模 ...
- SpringBoot入门教程(二十)Swagger2-自动生成RESTful规范API文档
Swagger2 方式,一定会让你有不一样的开发体验:功能丰富 :支持多种注解,自动生成接口文档界面,支持在界面测试API接口功能:及时更新 :开发过程中花一点写注释的时间,就可以及时的更新API文档 ...
- 用python批量生成简单的xml文档
最近生成训练数据时,给一批无效的背景图片生成对应的xml文档,我用python写了一个简单的批量生成xml文档的demo,遇见了意外的小问题,记录一下. 报错问题为:ImportError: No m ...
随机推荐
- C#实现:给定任意要给字符串,输出所有可能的回文的子字符串集合。
class Program { static void Main(string[] args) { string testStr = "sdfadfdsfadfdsfsdf"; i ...
- SQL触发器实例讲解
SQL触发器实例1 定义: 何为触发器?在SQL Server里面也就是对某一个表的一定的操作,触发某种条件,从而执行的一段程序.触发器是一个特殊的存储过程. 常见的触发器有三种:分别应用于Inser ...
- Linux SVN 命令详解(zz)
Linux下常用SVN命令 2012-04-02 11:46:00 标签:服务器 目录 Linux checkout linux系统 1.将文件checkout到本地目录 svn checkout p ...
- js获取单选按钮的值
function a(){ var v=document.getElementsByName("radio"); ;i<v.length;i++){ if(v[i].chec ...
- ASP.NET c# textbox 正则表达式 文本框只允许输入数字(验证控件RegularExpressionValidator )
<input type="text" name="test" onKeyUp="test1.value=(this.value=this.val ...
- 1282 - Leading and Trailing ---LightOj1282(快速幂 + 数学)
http://lightoj.com/volume_showproblem.php?problem=1282 题目大意: 求n的k次方的前三位和后三位数然后输出 后三位是用快速幂做的,我刚开始还是不会 ...
- js中的定义
执行环境:执行环境定义了变量或函数有权访问的其他数据,决定了他们各自的行为,每个执行环境都有一个与之关联的 变量对象:环境中定义的所有变量和函数都保存在这个对象中.(在函数中这个变量对象叫活动对象) ...
- flask_分页
一.提交博客文章 1.定义一个单字段的表单对象(form.py) class PostForm(Form): post = StringField('post', validators=[DataRe ...
- switch的经典引用
#include<stdio.h> int main(void) { int i; do{ printf("按1,流量查询\n"); printf("按2,人 ...
- Linux下Bash入门学习笔记
学习好shell编程是很有用的,可以使用shell脚本轻巧地完成有趣的工作. 本文地址:http://www.cnblogs.com/yhLinux/p/4047516.html 1. Bash实例, ...