Word VBA实现光标移至新行:两种尝试方法无效,求解决方案
Word VBA 实现光标跳转至新行的有效方法
你之前的两种代码仅插入了换行符,但未将光标定位到新行,所以看似没生效。以下是几种能直接将光标移至新行的有效写法:
- 插入换行后手动调整光标位置:
Selection.InsertAfter vbCrLf Selection.Collapse Direction:=wdCollapseEnd Selection.MoveLeft Unit:=wdCharacter, Count:=1
- 模拟手动输入回车(最直观的方式):
Selection.TypeText Text:=vbCrLf
- 通过添加新段落定位光标:
Dim newPara As Paragraph Set newPara = Selection.Paragraphs.Add(Selection.Paragraphs(Selection.Paragraphs.Count).Range) newPara.Range.Select
内容的提问来源于stack exchange,提问作者maher kochbati
相关产品推荐
相关产品推荐

