| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1556 人关注过本帖
标题:怎样添加页脚
只看楼主 加入收藏
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
结帖率:100%
收藏
 问题点数:0 回复次数:2 
怎样添加页脚
向大侠求助:用VB调试word文档,文字修改存盘成功了。现在不懂页脚怎样写程序,问度娘终没正果。
Public Sub Ca涵()
  Set WordApp = CreateObject("Word.Application")
 '   WordApp.Visible = True
  Set Word = WordApp.Documents.Open(App.Path & "\存放夹\分部_涵洞.doc")
    Word.Tables(1).Cell(2, 1) = Str项目名
    Word.Tables(1).Cell(4, 1) = Str分部名 & "分部工程验收报告"
    Word.Tables(1).Cell(5, 1) = Str简 & "[" & Year年 & "]分验" & Num分部序号 & "号"
    Word.Tables(1).Cell(10, 2) = Str单项名
    Word.Tables(1).Cell(11, 2) = Str单位名
    Word.Tables(1).Cell(12, 2) = Str分部名
    Word.Tables(1).Cell(14, 1) = Str分部名 & "分部工程验收组"
    Word.Tables(1).Cell(15, 1) = Ymd年月日


Dim r As Range
'给文档的第一节页脚添加页码
Set r = Word.Sections(1).Footers.Range     '运行显示“实时错误'438'对象不支持该属性或方法”
With r
    .InsertAfter "第"
    .Font.Size = 20
    .Collapse Direction:=wdCollapseEnd
    '插入页码域
    .Fields.Add Range:=r, Type:=wdFieldEmpty, Text:= _
        "PAGE  \* Arabic ", PreserveFormatting:=True
    .Expand unit:=wdWord
    .InsertAfter "页 "
     
    .InsertAfter "共"
     .Collapse Direction:=wdCollapseEnd
     '插入页数域
    .Fields.Add Range:=r, Type:=wdFieldEmpty, Text:= _
        "NUMPAGES  \* Arabic ", PreserveFormatting:=True
    .Expand unit:=wdWord
    .InsertAfter "页"
 
    .InsertAfter "'" & Str分部名 & "_" & Str简 & "  "
    .ParagraphFormat.Alignment = wdAlignParagraphRight
End With
'隐藏页眉的横线
Word.Sections(1).Headers(wdHeaderFooterPrimary).Range.Borders(wdBorderBottom).Visible = False

    Word.SaveAs (Print打印夹 & "\分部工程\涵分部\涵洞(" & "_" & Str分部名 & "_" & Str简 & ").doc")      '另存  
    Word.Close
    WordApp.Quit
    Set Word = Nothing
    Set WordApp = Nothing
End Sub
搜索更多相关主题的帖子: Cell Str Tables Word Set 
2019-11-30 16:33
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:0 
希望得到版主的指教

调试失败3次后,关机睡觉,当醒来时多有收获。
2019-12-01 09:17
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:0 
我自己玩了几次,借助VBA终于完成任务,发上群,供大家学习
Public Sub Ca涵()
  Set WordApp = CreateObject("Word.Application")
 '   WordApp.Visible = True
  Set Word = WordApp.Documents.Open(App.Path & "\存放夹\分部_涵洞.doc")
    Word.Tables(1).Cell(2, 1) = Str项目名
    Word.Tables(1).Cell(4, 1) = Str分部名 & "分部工程验收报告"
    Word.Tables(1).Cell(5, 1) = Str简 & "[" & Year年 & "]分验" & Num分部序号 & "号"
    Word.Tables(1).Cell(10, 2) = Str单项名
    Word.Tables(1).Cell(11, 2) = Str单位名
    Word.Tables(1).Cell(12, 2) = Str分部名
    Word.Tables(1).Cell(14, 1) = Str分部名 & "分部工程验收组"
    Word.Tables(1).Cell(15, 1) = Ymd年月日

   Word.Sections(1).Headers(wdHeaderFooterPrimary).Range.Text = Str分部名 & "工程验收"          '设置页眉
    Word.Sections(1).Footers(wdHeaderFooterPrimary).PageNumbers.Add                      '设置页脚
    Word.SaveAs (Print打印夹 & "\分部工程\涵分部\涵洞(" & "_" & Str分部名 & "_" & Str简 & ").doc")      '另存  
    Word.Close
    WordApp.Quit
    Set Word = Nothing
    Set WordApp = Nothing
End Sub

调试失败3次后,关机睡觉,当醒来时多有收获。
2019-12-19 22:58
快速回复:怎样添加页脚
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014890 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved