Sub mainProc()
Application.ScreenUpdating = False
Application.DisplayAlerts = wdAlertsNone 'Dim xlApp As Excel.Application
'Dim Wb As Excel.Workbook
'Dim Sht As Excel.Worksheet
Dim xlApp As Object
Dim Wb As Object
Dim sht As Object
Dim EndRow As Long
Dim Arr As Variant
Dim xlRng As Object 'Excel.Range Dim TmpDoc As Document
Dim NewName As String
Dim NewPath As String 'Set xlApp = New Excel.Application
Set xlApp = CreateObject("Excel.Application")
Set Wb = xlApp.Workbooks.Open(ActiveDocument.Path & "\附件4 党员基本信息汇总表.xls")
Set sht = Wb.Worksheets(1)
With sht
For i = 21 To 5 Step -1
If .Cells(i, 2).Value <> "" Then
EndRow = i
Exit For
End If
Next i
Set xlRng = .Range("A5:T" & EndRow)
Arr = xlRng.Value
End With Wb.Close False
xlApp.Quit Const TmpName As String = "采集表.doc" For i = LBound(Arr) To UBound(Arr)
Set TmpDoc = Application.Documents.Open(ActiveDocument.Path & "\" & TmpName)
TmpDoc.Activate '姓名
FindReplace "Name", Arr(i, 2)
'性别
If Arr(i, 5) = "男" Then
FindTrue = "nan"
FindFalse = "nv"
FindTrueAndFalse FindTrue, FindFalse
Else
FindTrue = "nv"
FindFalse = "nan"
FindTrueAndFalse FindTrue, FindFalse
End If
'民族
FindReplace "mz", Split(Arr(i, 6), " ")(1)
'身份证加框
FindText = "id"
InputText = Arr(i, 4)
FindAndInput FindText, InputText '出生日期
bir = Format(Arr(i, 7), "yyyy/mm/dd")
FindReplace "yyy1", Split(bir, "/")(0)
FindReplace "m1", Split(bir, "/")(1)
FindReplace "d1", Split(bir, "/")(2) '学历代码加框
FindText = "XL"
InputText = Split(Arr(i, 8), " ")(0)
FindAndInput FindText, InputText '正式预备
If Arr(i, 9) = "正式党员" Then
FindTrue = "zs"
FindFalse = "yb"
FindTrueAndFalse FindTrue, FindFalse
Else
FindTrue = "yb"
FindFalse = "zs"
FindTrueAndFalse FindTrue, FindFalse
End If
'党支部
FindReplace "dzb", Arr(i, 3) '加入日期
bir = Format(Arr(i, 10), "yyyy/mm/dd")
FindReplace "yyy2", Split(bir, "/")(0)
FindReplace "m2", Split(bir, "/")(1)
FindReplace "d2", Split(bir, "/")(2) '转正日期
bir = Format(Arr(i, 11), "yyyy/mm/dd")
FindReplace "yyy3", Split(bir, "/")(0)
FindReplace "m3", Split(bir, "/")(1)
FindReplace "d3", Split(bir, "/")(2) '工作岗位代号加框
FindText = "gzgw"
InputText = Split(Arr(i, 12), " ")(0)
FindAndInput FindText, InputText '手机号码加框
FindText = "cell"
InputText = Arr(i, 13)
FindAndInput FindText, InputText '区号加框
FindText = "zone"
InputText = Split(Arr(i, 14), "-")(0)
FindAndInput FindText, InputText '固话加框
FindText = "phone"
InputText = Split(Arr(i, 14), "-")(1)
FindAndInput FindText, InputText '家庭地址
FindReplace "adr", Arr(i, 15) '正常停止
If Arr(i, 16) = "正常" Then
FindTrue = "zc"
FindFalse = "tz"
FindTrueAndFalse FindTrue, FindFalse
Else
FindTrue = "tz"
FindFalse = "zc"
FindTrueAndFalse FindTrue, FindFalse
End If '是否失联
If Arr(i, 17) = "是" Then
FindTrue = "yes1"
FindFalse = "no1"
FindTrueAndFalse FindTrue, FindFalse
Else
FindTrue = "no1"
FindFalse = "yes1"
FindTrueAndFalse FindTrue, FindFalse
End If '失恋日期
If Arr(i, 17) = "是" Then
bir = Format(Arr(i, 18), "yyyy/mm")
FindReplace "yyy4", Split(bir, "/")(0)
FindReplace "m4", Split(bir, "/")(1)
Else
FindReplace "yyy4", ""
FindReplace "m4", ""
End If '是否流出
If Arr(i, 19) = "是" Then
FindTrue = "yes2"
FindFalse = "no2"
FindTrueAndFalse FindTrue, FindFalse
Else
FindTrue = "no2"
FindFalse = "yes2"
FindTrueAndFalse FindTrue, FindFalse
End If '流出省市县
If Arr(i, 19) = "是" Then FindReplace "sheng", Split(Arr(i, 20), "-")(0)
FindReplace "shi", Split(Arr(i, 20), "-")(1)
FindReplace "xian", Split(Arr(i, 20), "-")(2)
Else
FindReplace "sheng", ""
FindReplace "shi", ""
FindReplace "xian", ""
End If
NewName = Arr(i, 2) & "-" & TmpName
NewPath = ActiveDocument.Path & "\批量生成文件\" & NewName On Error Resume Next
Kill NewPath
On Error GoTo 0 TmpDoc.SaveAs2 NewPath
TmpDoc.Close Next i MsgBox "Done!"
Application.ScreenUpdating = True
Application.DisplayAlerts = wdAlertsAll
End Sub Sub FindTrueAndFalse(ByVal FindTrue As String, ByVal FindFalse As String) Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindTrue
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne
Selection.InsertSymbol Font:="Wingdings 2", CharacterNumber:=-4014, Unicode:=True
End With Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindFalse
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne
Selection.InsertSymbol Font:="宋体", CharacterNumber:=9633, Unicode:=True
End With End Sub
Public Sub FindAndInput(ByVal FindText As String, ByVal InputText As String)
Dim Rng As Range
Dim RngStart As Long, RngEnd As Long
Selection.HomeKey wdStory With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindText
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne
RngStart = Selection.Start
For i = 1 To Len(InputText)
Selection.Collapse wdCollapseEnd
Selection.Range.ModifyEnclosure Style:=wdEncloseStyleSmall, Symbol:= _
wdEnclosureSquare, EnclosedText:=Mid(InputText, i, 1)
Selection.MoveRight wdCharacter, 1
Next i
RngEnd = Selection.Start
Set Rng = ActiveDocument.Range(RngStart, RngEnd)
SetFont Rng
End With
Set Rng = Nothing
End Sub
Public Sub SetFont(ByVal Rng As Range)
With Rng.Font
.Name = "黑体"
.Size = 14
End With
End Sub
Public Sub FindReplace(ByVal FindText As String, ByVal RepText As String)
Selection.HomeKey wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FindText
.Replacement.Text = RepText
.Forward = True
.Wrap = wdFindStop
.Execute Replace:=wdReplaceOne
End With
End Sub

  

20170612xlVBA含方框文档填表的更多相关文章

  1. 近200篇机器学习&深度学习资料分享(含各种文档,视频,源码等)(1)

    原文:http://developer.51cto.com/art/201501/464174.htm 编者按:本文收集了百来篇关于机器学习和深度学习的资料,含各种文档,视频,源码等.而且原文也会不定 ...

  2. 这可能是最详细的 iOS 学习入门指南(含书目/文档/学习资料)

    1 零基础小白如何进行 iOS 系统学习 首先,学习目标要明确: 其次,有了目标,要培养兴趣,经常给自己一些正面的反馈,比如对自己的进步进行鼓励,在前期小步快走: 再次,学技术最重要的一点就是多动手. ...

  3. 阿里P7Java最全面试296题:阿里天猫、蚂蚁金服含答案文档解析

    [阿里天猫.蚂蚁.钉钉面试专题题目加答案] 不会做别着急:文末有答案以及视频讲解,架构师资料 1. junit用法,before,beforeClass,after, afterClass的执行顺序 ...

  4. jQuery LigerUI 最新版压缩包(含chm帮助文档、源码、donet权限示例)

    jQuery LigerUI 最新版压缩包 http://download.csdn.net/download/heyin12345/4680593 jQuery LigerUI 最新版压缩包(含ch ...

  5. ABP 教程文档 1-1 手把手引进门之 AngularJs, ASP.NET MVC, Web API 和 EntityFramework(官方教程翻译版 版本3.2.5)含学习资料

    本文是ABP官方文档翻译版,翻译基于 3.2.5 版本 转载请注明出处:http://www.cnblogs.com/yabu007/  谢谢 官方文档分四部分 一. 教程文档 二.ABP 框架 三. ...

  6. Java进阶(十九)利用正则表达式批处理含链接内容文档

    利用正则表达式批处理含链接内容文档 由于项目需求,自己需要将带有链接的标签去除,例如 <a href="/zhaoyao/17-66.html">头晕</a> ...

  7. 提取一个txt 文档中含指定字符串的所有行

    将一个txt 文档中含指定字符串内容的所有行提取出来并保存至新的txt文档中 例如,要提取 1.txt 中所有包含”aaa” 的行的内容 只需在此文件夹中新建一个bat文件,输入以下代码,双击运行,便 ...

  8. 介绍一款jquery ui组件gijgo(含tree树状结构、grid表格),特点:简易、文档全清晰易懂、示例代码

    http://gijgo.com   gijgo组件 特点:简易.文档全-虽然是英文的但是清晰易懂可读性强.含示例代码(后端直接用原生.Net C# MVC的哦!非常合.Net开发胃口),网站网速快, ...

  9. MultiThread(VS2013 MFC多线程-含源码-含个人逐步实现文档)

    原文:http://download.csdn.net/download/jobfind/9559162 MultiThread(VS2013 MFC多线程-含源码-含个人逐步实现文档).rar

随机推荐

  1. MySQL从删库到跑路_高级(一)——数据完整性

    作者:天山老妖S 链接:http://blog.51cto.com/9291927 一.数据完整性简介 1.数据完整性简介 数据冗余是指数据库中存在一些重复的数据,数据完整性是指数据库中的数据能够正确 ...

  2. Masonry 适配label多行

    设置属性后,然后根据文本自动多行显示,无需设置标签高度约束 1 属性preferredMaxLayoutWidth,如:label.preferredMaxLayoutWidth = (WidthSc ...

  3. 聊聊WKWebView

    聊一聊WKWebView 前言 由于之前一直在用UIWebView,所以对于WKWebView只是停留在知道,了解的状态,并未深入的去研究.前天一个项目要求支持iOS8以上,要加入一个web界面.在习 ...

  4. VMWare中桥接、NAT、Host-only

    1.概述 2.bridged(桥接模式) 3.NAT(网络地址转换模式) 4.host-only(主机模式) 5.replicate physical network connection state ...

  5. SQL语句常见优化方法

    Sql优化方法 先进行选择运算(where limit)再进行连接运算 where子句中应把过滤性最强的条件放在最前面 where子句中字段的顺序应和组合索引中字段顺序一致 使用索引 使用覆盖索引来避 ...

  6. LLVM/Clang编译相关研究

    https://blog.csdn.net/guojin08/article/details/54310858 https://juejin.im/entry/5c64da44518825620b45 ...

  7. mysql修改Truncated incorrect DOUBLE value:

    UPDATE shop_category SET name = 'Secolul XVI - XVIII' AND name_eng = '16th to 18th centuries' WHERE ...

  8. Django框架----models.py(数据库操作文件)

    利用一个中间模块 帮助我们连接数据库,写SQL语句,执行SQL语句,拿到结果 models.py 一.数据的对应关系 1. 类 ---> 表 2. 对象 ---> 数据行 3. 属性 -- ...

  9. 20145307陈俊达《网络对抗》Exp7 网络欺诈技术防范

    20145307陈俊达<网络对抗>Exp7 网络欺诈技术防范 基础问题回答 什么是dns欺骗攻击! 利用dns spoof运行DNS欺骗,如果是请求解析某个域名,dnsspoof会让该域名 ...

  10. 我在linux中使用的vundle 和 vimrc配置

    set nocompatible filetype off set rtp+=~/.vim/bundle/vundle/ call vundle#rc() Plugin 'gmarik/vundle' ...