|
写了一个VBS脚本,但是还没写完,不过你可以参考下代码自己修改,中间录宏做的,因为对WORD不熟,搞的乱七八糟
直接复制代码到你的文件夹中新建txt文档,另存为,后缀txt改为VBS即可(前提是调试完能用)
本来是想打开模板文件替换的,但是不知道什么原因不能完成替换,所以成现在这个样子了,半夜12点,不想再继续下去了,有空再说吧
声明:以下代码只是半成品,仅供参考,不能拿来用,出问题鄙人不负责,哈哈
- Dim WordApp,FSO
- Dim MyTemplate,MyBook,DataArr,MyDoc
- Dim i,n,MyPath,Arr1,Arr2
- Set FSO=CreateObject("scripting.filesystemobject")
- MyPath = FSO.GetFile(WScript.ScriptFullName).ParentFolder.Path
- If Right(MyPath,1)<>"" Then MyPath=MyPath&""
- Set WordApp=CreateObject("Word.Application")
- Set Mybook=GetObject(MyPath & "统计表.xls")
- If MyBook Is nothing Then MsgBox "找不到数据源表格!",64,"提示" : WScript.Quit
- DataArr= MyBook.sheets(1).usedrange
- MyBook.close False
- Set MyBook=nothing
- Arr1=Array(1,3,4,5,6,7)
- FSO.CreateFolder MyPath & "通知书"
- Set FSO=nothing
- MyPath=MyPath &"通知书"
- WordApp.ScreenUpdating=false
- For i = 2 To 5'UBound(dataarr) '<----此处调试完成后需要修改
- Set MyDoc=WordApp.Documents.Add
- With MyDoc.ActiveWindow.Selection
-
- .Font.Size=16
- .ParagraphFormat.Alignment = wdAlignParagraphRight
- .TypeText DataArr(i,1)
- .TypeParagraph
- .ParagraphFormat.Alignment = wdAlignParagraphCenter
- .Font.Color = wdColorRed
- .Font.Size = 26
- .Font.Bold = wdToggle
- .TypeText text="名 流 置 业 有 限 公 司 信 笺"
- With MyDoc.Shapes.AddLine(30,300,300,300)
- .Height= 3
- .Fill.color=vbred
- End With
- .Font.Color = wdColorAutomatic
- .TypeParagraph
- .TypeText "补发工资通知书"
- .TypeParagraph
- .ParagraphFormat.Alignment = wdAlignParagraphLeft
- .Font.Underline = wdUnderlineSingle
- .TypeText(" " & DataArr(i,3) &" ")
- .Font.Underline = wdUnderlineNone
- .TypeText text="同志:"
- .TypeParagraph
- .TypeText Text=vbtab & "经上级批准,确定从2008年7月1日起,调整工资标准,按照有关文件规定,依据你的工龄,确定补发2009年7月至" & DataArr(i,4) & "的工资差额共计" & DataArr(i,4) & "元,大写" & DataArr(i,5) & ",已通过" & DataArr(i,6) &"发给你,请注意查收。"
- .TypeParagraph
- .TypeText Text=vbTab &"特此通知."
- .TypeParagraph
- .TypeParagraph
- .TypeText Text=Space(20)&"单位:(盖章)"
- .TypeParagraph
- .TypeParagraph
- .TypeText Text=Space(20)&"二〇一一年五月二十八日"
-
- End with
- With MyDoc
- .SaveAs MyPath & DataArr(i,1) &".doc"
- .close
- End With
- Next
- MyTemplate.Close False
- Set MyTemplate=Nothing
- WordApp.Quit
- Set WordApp=Nothing
- MsgBox "批量合并通知书操作完成,文件存放在" &vbcrlf & MyPath &" 目录下!",64,"提示"
- WScript.quit
- Er:
- MyTemplate.Close False
- Set MyTemplate=Nothing
- WordApp.ScreenUpdating=true
- WordApp.Quit
- Set WordApp=Nothing
- WScript.Quit
复制代码
[ 本帖最后由 xtanuihazfh 于 2011-6-8 00:08 编辑 ] |
|