Foxtable(狐表)用户栏目专家坐堂 → 怎么从一个模板里面复制页脚呢?


  共有4100人关注过本帖树形打印复制链接

主题:怎么从一个模板里面复制页脚呢?

帅哥哟,离线,有人找我吗?
cnsjroom
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
怎么从一个模板里面复制页脚呢?  发帖心情 Post By: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

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)参考:https://docs.microsoft.com/z...  发帖心情 Post By:2021/6/7 12:03: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.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

这样运行的话  结果页眉页脚都是页脚的内容了    老师怎么修正呢?

 回到顶部
帅哥哟,离线,有人找我吗?
有点蓝
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:超级版主 帖子:111393 积分:567029 威望:0 精华:9 注册:2015/6/24 9:21:00
  发帖心情 Post By: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
  5楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:七尾狐 帖子:1571 积分:11238 威望:0 精华:0 注册:2021/1/17 17:06:00
回复:(有点蓝)分开处理,先处理页眉。在使用同样的...  发帖心情 Post By: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

 回到顶部