注册 登录
编程论坛 VB6论坛

VB VBA 能否将光标定位到WORD第三段的段尾,谢谢

ygxshanghai 发布于 2022-01-13 15:51, 1789 次点击
VB VBA 能否将光标定位到WORD第三段的段尾,谢谢
Option Explicit

Private Sub Command1_Click()
Dim wordApp As Word.Application, Word As Document
Set wordApp = CreateObject("Word.Application") '加入各服务中心的头一张“合格供方复评记录”代码
Set Word = wordApp.Documents.Open(App.Path & "\11111.doc")
wordApp.Visible = False


'将光标定位到WORD第三段的段尾



Word.SaveAs App.Path & "\11111.doc"
Word.Close
Set Word = Nothing
wordApp.Quit
Set wordApp = Nothing
End Sub
只有本站会员才能查看附件,请 登录
3 回复
#2
独木星空2022-01-14 07:06
回复 楼主 ygxshanghai
我倒是孤陋寡闻,用vb6也能定位光标?看来有时间,真的好好学学。
#3
wds12022-01-14 21:13
Option Explicit

Private Sub Command1_Click()
Dim wordApp As Word.Application, Word As Document
Set wordApp = CreateObject("Word.Application") '加入各服务中心的头一张“合格供方复评记录”代码
Set Word = wordApp.Documents.Open(App.Path & "\11111.doc")
wordApp.Visible = False

'将光标定位到WORD第三段的段尾
Word.SaveAs App.Path & "\11111.doc"
'==============【新增定位和插入数据】======================
  wordApp.Selection.Find.Text = "^p"'设置查找硬回车
  wordApp.Selection.Find.Execute '执行3次查找,相当于定位到第三段段尾
  wordApp.Selection.Find.Execute
  wordApp.Selection.Find.Execute
  wordApp.Selection.TypeText Text:="【插入行文本】"'在第三段段尾插入新文本
'==============【新增定位和插入数据】======================  
Word.Close
Set Word = Nothing
wordApp.Quit
Set wordApp = Nothing
End Sub
#4
ygxshanghai2022-01-17 09:43
回复 3楼 wds1
OK,正确
1