永发信息网

用vb如何替换word中的页脚

答案:2  悬赏:50  手机版
解决时间 2021-03-10 07:52
  • 提问者网友:鐵馬踏冰河
  • 2021-03-09 15:45
我用vb写了一段程序可以替换word中的指定字符且word的版式及字体都不改变,但是就是word中的页脚替换不了,请问如何替换,高手指点一下,谢谢
最佳答案
  • 五星知识达人网友:第四晚心情
  • 2021-03-09 15:54
可以先在word中录制一段VB代码的宏,主要修改页脚,作参考调用:

Sub Macro1()
'
' Macro1 Macro
' 宏在 2008-5-23 由 微软用户 录制
'
If ActiveWindow.View.SplitSpecial <> wdPaneNone Then
ActiveWindow.Panes(2).Close
End If
If ActiveWindow.ActivePane.View.Type = wdNormalView Or ActiveWindow. _
ActivePane.View.Type = wdOutlineView Then
ActiveWindow.ActivePane.View.Type = wdPrintView
End If
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
If Selection.HeaderFooter.IsHeader = True Then
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageFooter
Else
ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
End If
Selection.TypeText Text:="2008 "
Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldNumPages
ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
End Sub

以上宏中,我主要在页脚插入2008,以及页码
全部回答
  • 1楼网友:廢物販賣機
  • 2021-03-09 17:13
先工程引入microsoft word 接下来的代码你可以参考word中的宏,代码全有了。 例: dim xx as new word.application with xx.documents.open("c:\1.doc") with .content .find.execute "ask",false,false,false,false,false,true,1,false,me.text1.text,2,false,false,false,false end with end with 初学可能还没找到引入在哪,下面的代码可以不引入dll 直接放到vb里就可以,加个按钮喔,还有是vb6.0 private sub command1_click() dim wordobj set wordobj = createobject("word.application") with wordobj.documents.open("c:\1.doc")'word文档路径 with .content if .find.execute("ask") then .text = me.text1.text end if end with .save end with wordobj.quit end sub
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯