1. word vba怎样把光标定位到指定字符串的位置
移动光标至文档开始 Selection.HomeKey unit:=wdStory 下面的供参考:Sub MoveToCurrentLineStart()'移动光标至当前行首 Selection.HomeKey unit:=wdLine End Sub Sub MoveToCurrentLineEnd()'移动光标至当前行尾 Selection.EndKey unit:=wdLine End Sub Sub SelectToCurrentLineStart()'选择从光标至当前行首的内容 Selection.HomeKey unit:=wdLine, Extend:=wdExtend End Sub Sub SelectToCurrentLineEnd()'选择从光标至当前行尾的内容 Selection.EndKey unit:=wdLine, Extend:=wdExtend End Sub Sub SelectCurrentLine()'选择当前行 Selection.HomeKey unit:=wdLine Selection.EndKey unit:=wdLine, Extend:=wdExtend End Sub Sub MoveToDocStart()'移动光标至文档开始 Selection.HomeKey unit:=wdStory End Sub Sub MoveToDocEnd()'移动光标至文档结尾 Selection.EndKey unit:=wdStory End Sub Sub SelectToDocStart()'选择从光标至文档开始的内容 Selection.HomeKey unit:=wdStory, Extend:=wdExtend End Sub Sub SelectToDocEnd()'选择从光标至文档结尾的内容 Selection.EndKey unit:=wdStory, Extend:=wdExtend End Sub Sub SelectDocAll()'选择文档全部内容(从WholeStory可猜出Story应是当前文档的意思) Selection.WholeStory End Sub Sub MoveToCurrentParagraphStart()'移动光标至当前段落的开始 Selection.MoveUp unit:=wdParagraph End Sub Sub MoveToCurrentParagraphEnd()'移动光标至当前段落的结尾 Selection.MoveDown unit:=wdParagraph End Sub Sub SelectToCurrentParagraphStart()'选择从光标至当前段落开始的内容 Selection.MoveUp unit:=wdParagraph, Extend:=wdExtend End Sub Sub SelectToCurrentParagraphEnd()'选择从光标至当前段落结尾的内容 Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend End Sub Sub SelectCurrentParagraph()'选择光标所在段落的内容 Selection.MoveUp unit:=wdParagraph Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend End Sub Sub DisplaySelectionStartAndEnd()'显示选择区的开始与结束的位置,注意:文档第1个字符的位置是0 MsgBox ("第" & Selection.Start & "个字符至第" & Selection.End & "个字符") End Sub Sub DeleteCurrentLine()'删除当前行 Selection.HomeKey unit:=wdLine Selection.EndKey unit:=wdLine, Extend:=wdExtend Selection.Delete End Sub Sub DeleteCurrentParagraph()'删除当前段落 Selection.MoveUp unit:=wdParagraph Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend Selection.Delete End Sub。
2. word 宏 定位光标 代码
这个好象无法实现,MoveDown的wdUnits中没有页的选项。
我在实际操作中是通过查找某一个关键字,然后在用Selection.Movedown或MoveRight、MoveLeft、MoveUp等。比如:Sub Macro1()Selection.HomeKey wdStory '把光标移到最开始Selection.Find.Execute "Job Description" '查找第一个“Job Description”Selection.MoveLeft '光标移到第字母J的左边End Sub以上假设第2页的第一行第一列里又”Job Description"这词。
3. 用宏批量定位word中图片位置
帮你稍微修改了一下,使所有嵌入式图片居中。
对于所有图片,可以用ActiveDocument.Shapes.Count
注意:这里的Shapes(InlineShapes)不仅仅是指图片,也包含其它的,自选图形、任意多边形、OLE 对象、ActiveX 控件、图片等。
Sub setpicsize()
'设置图片大小
' 宏在 2008-3-31 由 hero_thm 录制
'
Dim j '计数图片个数
For j = 1 To ActiveDocument.InlineShapes.Count '文件中图片总个数,图片类型为inlineshapes
ActiveDocument.InlineShapes(j).Select '选中图片
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter '图片居中;wdAlignParagraphLeft左对齐
Next j
End Sub
上面,我补充的语句,其实也是录制宏的方式,生成的。(先选中图片,再点居中按钮)
另外,学习宏,多看看Word自带的帮助文档吧。
==========2008-4-16========
Sub setpicsize()
'
Dim j '计数图片个数
For j = 1 To ActiveDocument.InlineShapes.Count '文件中图片总个数,图片类型也可以为shapes
ActiveDocument.InlineShapes(j).Select '选中图片
'ActiveDocument.InlineShapes(j).Range.Paragraphs(1).Range.Select '上一行不行,用这个
With Selection.ParagraphFormat '所选段落的格式
.Alignment = wdAlignParagraphCenter '图片居中
.LeftIndent = 0 '左缩进磅数
.RightIndent = 0 '右缩进磅数
.FirstLineIndent = 0 '首行缩进磅数
.CharacterUnitLeftIndent = 0 '左缩进字符数
.CharacterUnitRightIndent = 0 '右缩进字符数
.CharacterUnitFirstLineIndent = 0 '首行缩进字符数
End With
Next j
End Sub
4. word 宏 定位光标 代码
这个好象无法实现,MoveDown的wdUnits中没有页的选项。我在实际操作中是通过查找某一个关键字,然后在用Selection.Movedown或MoveRight、MoveLeft、MoveUp等。比如:
Sub Macro1()
Selection.HomeKey wdStory '把光标移到最开始
Selection.Find.Execute "Job Description" '查找第一个“Job Description”
Selection.MoveLeft '光标移到第字母J的左边
End Sub
以上假设第2页的第一行第一列里又”Job Description"这词。
5. word vba怎么查找字符串,并获取所在页码、所在行数
Private Sub CommandButton1_Click()
Dim p, r, s, t
s= "石膏板造型顶"
With Selection.Find
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
t = .Execute(FindText:=s)
End With
p= Selection.Information(wdActiveEndPageNumber)
r= Selection.Information(wdFirstCharacterLineNumber)
If t Then
MsgBox "成功,已找到“" & s & "”" & vbCrLf & _
"页码:"& p & vbCrLf &; "行数:" & r, vbOKOnly, _
"成功"
Else
MsgBox "很遗憾,没有找到“" & s & "”", vbOKOnly, _
"遗憾"
End If
End Sub 写代码很辛苦,好心的楼主请 救济 点儿 悬赏分
转载请注明出处51数据库 » word宏定位字符串