以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 怎么从一个模板里面复制页脚呢? (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=169202) |
-- 作者:cnsjroom -- 发布时间:2021/6/7 10:01:00 -- 怎么从一个模板里面复制页脚呢? 怎么从一个模板里面复制页脚呢? 下述代码是实现了页眉的复制 怎么补充实现页眉也复制过来呢? Dim app As New MSWord.Application try Dim doc0 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc0.Close Dim fileName = "d:\\test.docx" Dim doc As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally \'app.Quit End try
|
-- 作者:有点蓝 -- 发布时间:2021/6/7 10:03:00 -- 参考:https://docs.microsoft.com/zh-cn/office/vba/api/word.wdseekview app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter
|
-- 作者:cnsjroom -- 发布时间:2021/6/7 12:03:00 -- 回复:(有点蓝)参考:https://docs.microsoft.com/z... Dim app As New MSWord.Application try Dim doc0 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc0.Close Dim doc01 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc01.Close Dim fileName = "d:\\test.docx" Dim doc As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.Visible = True Dim doc1 As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally \'app.Quit End try 这样运行的话 结果页眉页脚都是页脚的内容了 老师怎么修正呢?
|
-- 作者:有点蓝 -- 发布时间:2021/6/7 12:25:00 -- 分开处理,先处理页眉。在使用同样的代码设置页脚,不要混在一起使用 Dim app As New MSWord.Application try Dim doc0 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc0.Close Dim fileName = "d:\\test.docx" Dim doc As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument 这里复制上面代码另外处理页脚 app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally \'app.Quit End try |
-- 作者:cnsjroom -- 发布时间:2021/6/7 14:40:00 -- 回复:(有点蓝)分开处理,先处理页眉。在使用同样的... 老师 在你的指导下 已经可以成功从模板复制页眉和页脚了 谢谢! Dim app As New MSWord.Application try Dim doc0 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc0.Close Dim fileName = "d:\\test.docx" Dim doc As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Dim doc10 As Object = app.Documents.Open("d:\\test2.docx") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Copy app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument Doc10.Close Dim fileName1 = "d:\\test.docx" Dim do1c As Object = app.Documents.Open(fileName1) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.Paste app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally \'app.Quit End try 以下信息备用:直接设定页眉和页脚 Dim app As New MSWord.Application try Dim fileName = "d:\\test.docx" Dim doc As Object = app.Documents.Open(fileName) app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageHeader app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Font.Size = 18 app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.TypeText(Text:="自己的页眉") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekCurrentPageFooter app.ActiveWindow.Selection.WholeStory app.ActiveWindow.Selection.Font.Size = 18 app.ActiveWindow.Selection.TypeBackspace app.ActiveWindow.Selection.TypeText(Text:="自己的页脚") app.ActiveWindow.ActivePane.View.SeekView = MSWord.WdSeekView.wdSeekMainDocument app.Visible = True catch ex As exception msgbox(ex.message) app.Quit finally \'app.Quit End try |