



免费预览已结束,剩余1页可下载查看
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Word文档根据关键字分页的VBA程序百度上有人提出这个问题,试着编了下,能实现。Sub 自动分页 Dim PagesKeywod As New Collection Dim StringKeywod As String Dim StringFileName As String StringKeywod = 关键字 StringFileName = 文件名 Selection.HomeKey Unit:=wdStory Selection.Find.ClearFormatting With Selection.Find .Text = StringKeywod .Replacement.Text = StringKeywod .Forward = True .Wrap = wdFindContinue .Format = False .MatchCase = False .MatchWholeWord = False .MatchByte = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute While (.Found = True) PagesKeywod.Add (Selection.Information(wdActiveEndPageNumber) .Execute Wend End With If PagesKeywod.Count = 0 Then MsgBox (没有找到关键字,不进行拆分文档处理。) ElseIf PagesKeywod.Count = 1 Then MsgBox (只有一个关键字,不进行拆分文档处理。) ElseIf PagesKeywod(1) = PagesKeywod(PagesKeywod.Count) Then MsgBox (所有关键字在同一页中,不进行拆分文档处理。) Else Dim Doc2 As Document Dim FileNo As Integer Dim PageStart As Integer PageStart = 1 Dim intStart As Integer Dim intEnd As Integer FileNo = 1 Selection.ExtendMode = True Selection.HomeKey Unit:=wdStory For i = 1 To PagesKeywod.Count - 1 If PagesKeywod(i) PagesKeywod(i + 1) Then ActiveDocument.Range(0, 1).Select Selection.GoTo wdGoToPage, wdGoToAbsolute, PageStart intStart = Selection.Start Selection.GoTo wdGoToPage, wdGoToAbsolute, PagesKeywod(i + 1) Selection.Move WdUnits.wdCharacter, -1 intEnd = Selection.End ActiveDocument.Range(intStart, intEnd).Copy PageStart = PagesKeywod(i + 1) Set Doc2 = Documents.Add(Template:=Normal, NewTemplate:=False, DocumentType:=0, Visible:=False) Doc2.Content.Paste ChangeFileOpenDirectory D: Doc2.SaveAs FileName:=StringFileName & FileNo & .doc, FileFormat:=wdFormatDocument, _ LockComments:=False, Password:=, AddToRecentFiles:=True, WritePassword _ :=, ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _ SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _ False FileNo = FileNo + 1 Doc2.Close End If Next i ActiveDocument.Range(0, 1).Select Selection.GoTo wdGoToPage, wdGoToAbsolute, PageStart intStart = Selection.Start Selection.EndKey Unit:=wdStory intEnd = Selection.End ActiveDocument.Range(intStart, intEnd).Copy Set Doc2 = Documents.Add(Template:=Normal, NewTemplate:=False, DocumentType:=0, Visible:=False) Doc2.Content.Paste ChangeFileOpenDirectory D: Doc2.SaveAs FileName:=StringFileName & FileNo & .doc, FileFormat:=wdFormatDocument, _ LockComments:=False, Password:=, AddToRecentFiles:=True, WritePassword _ :=, ReadOnlyRecommended:=False, Embe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 武汉市德才中学招聘初中教师3人考试参考试题及答案解析
- 2025贵州六盘水市水城区教育局银龄讲学计划教师招募50人备考考试题库附答案解析
- 2026上海申万宏源集团及证券秋季校园招聘备考考试题库附答案解析
- 成都市盐道街小学得胜分校公开招聘员额教师备考考试题库附答案解析
- 2025中国建筑一局(集团)有限公司基础设施分院水利设计岗招聘1人备考练习试题及答案解析
- 2025年蚌埠八中编外临聘教师招聘(第六批)备考考试题库附答案解析
- 掌握大学生活
- 防疫科普知识宣传
- 工厂安全培训心得课件
- 咨询服务供应链绿色化-洞察及研究
- 医院装修项目中的安全措施与难点处理
- 销售合规风险管理制度
- 药房员工销售培训
- 警校联动方案
- 让剪影动起来(教学设计)-2024-2025学年人教版(2012)美术六年级上册
- MBA硕士论文案例研究范文分享
- 五轴联动加工中心操作与基础编程 第2版 课件 1.1.1多轴机床与多轴加工类别
- 10 ai ei ui 教学设计-2024-2025学年语文一年级上册统编版
- 体育单招核心-1700-单词
- 《医院感染控制与医护人员个人防护》课件
- 2024六年级英语上册 Unit 2 Ways to go to school课时2 Let's learn-Write and say说课稿 人教PEP
评论
0/150
提交评论