这么简单的问题为什么就没人回答呢?
如果不用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页
发布评论