wordvba页

编程入门 行业动态 更新时间:2024-10-24 08:32:48
1.WORD VBA 指定任意页为当前页

这么简单的问题为什么就没人回答呢?

如果不用VBA更简单,编辑菜单--》定位 左面选 页,右边输入任意数字后确定就可以了。

用VBA的话其实就是用宏实现上面这个过程。

两句代码就可以了。

MyPageindex = InputBox("请输入页码:", "页码跳转")

Selection.GoTo What:=wdGoToPage, Which:=wdGoToAbsolute,Name:=MyPageindex

2.如何在word中使用VBA得出每一页都多少行文字啊

Sub LinesOfPage()

'方法很简单,就是数

Dim PageNo As Integer, Lines As Integer, MovedLines As Integer

'先确定现在的页码

PageNo = Selection.Information(wdActiveEndAdjustedPageNumber)

'行计数清零

Lines = 0

Do

'向上挪一行,如果到头了没挪动或挪到上一页去了就停止

If Selection.Move(wdLine, -1) = 0 Or PageNo Selection.Information(wdActiveEndAdjustedPageNumber) Then Exit Do

'还在同一页行数加1,继续挪

Lines = Lines + 1

Loop

'向下挪回开始的位置

Selection.Move wdLine, Lines

Do

'现在开始向下挪,,如果到尾了没挪动或挪到下一页去了就停止

If Selection.Move(wdLine, 1) = 0 Or PageNo Selection.Information(wdActiveEndAdjustedPageNumber) Then Exit Do

'还在同一页行数加1,继续挪

Lines = Lines + 1

Loop

'最后Lines就是这页的行数

End Sub

3.vba确定word指定文字在第几页

亲,代码如下,查找第一次出现“ABC”的所在页的页码。请根据情况自行修订需要查找的字符:

Sub cz()

Dim MyRange As Range

Set MyRange = ActiveDocument.Content

MyRange.Find.Execute FindText:="ABC", Forward:=True

MsgBox MyRange.Information(wdActiveEndPageNumber)

End Sub

4.word vba 在固定页 固定字后面添加指定内容

Sub test()

Dim Matches, N&

With CreateObject("vbscript.regexp")

.Global = True

.Pattern = "(^|[\r\n])([ \t\xa0]*\S\S条)"

If .test(ThisDocument.Range.Text) Then

Set Matches = .Execute(ThisDocument.Range.Text)

For N = Matches.Count - 1 To 0 Step -1

With Matches(N)

ThisDocument.Range(.firstindex + .Length, .firstindex + .Length).Text = "hello"

End With

Next N

End If

End With

End Sub

5.在excelvba中word复制插入整页

试试下面的代码,在网上找的 Sub 宏1() Dim wordapp As Object Dim mydoc Dim mypath$, myname$ Dim wdRng As Object Dim pos1%, pos2% '定义找到的字段的首位位置 Application.DisplayAlerts = False Set wordapp = CreateObject("word.application") mypath = ThisWorkbook.Path & "" myname = Dir(mypath & "*.doc*") Set mydoc = wordapp.Documents.Open(mypath & myname) Set wdRng = mydoc.Range wdRng.Find.Execute ("(一)") pos1 = wdRng.Start Set wdRng = mydoc.Range wdRng.Find.Execute ("五、") pos2 = wdRng.Start mydoc.Range(pos1, pos2).Copy '选中找到的两个字段中间的内容 mydoc.Close False wordapp.Quit Worksheets("Sheet2").Select Range("A1").Select ActiveSheet.Paste Application.ScreenUpdating = True Application.DisplayAlerts = TrueEnd Sub。

转载请注明出处51数据库 » wordvba

  • 0
  • 0
  • 0
  • 0
  • 0

更多推荐

wordvba页

本文发布于:2023-06-04 19:13:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/503400.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:wordvba

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!