在WORD中如何用VBA宏語(yǔ)言選定一行、一段,刪除一行、一段,移動(dòng)光標(biāo)至行首、行尾、段首、段尾等。請(qǐng)看以下內(nèi)容。
Sub MoveToCurrentLineStart()
'移動(dòng)光標(biāo)至當(dāng)前行首
Selection.HomeKey unit:=wdLine
End Sub
Sub MoveToCurrentLineEnd()
'移動(dòng)光標(biāo)至當(dāng)前行尾
Selection.EndKey unit:=wdLine
End Sub
Sub SelectToCurrentLineStart()
'選擇從光標(biāo)至當(dāng)前行首的內(nèi)容
Selection.HomeKey unit:=wdLine, Extend:=wdExtend
End Sub
Sub SelectToCurrentLineEnd()
'選擇從光標(biāo)至當(dāng)前行尾的內(nèi)容
Selection.EndKey unit:=wdLine, Extend:=wdExtend
End Sub
Sub SelectCurrentLine()
'選擇當(dāng)前行
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
End Sub
Sub MoveToDocStart()
'移動(dòng)光標(biāo)至文檔開(kāi)始
Selection.HomeKey unit:=wdStory
End Sub
Sub MoveToDocEnd()
'移動(dòng)光標(biāo)至文檔結(jié)尾
Selection.EndKey unit:=wdStory
End Sub
Sub SelectToDocStart()
'選擇從光標(biāo)至文檔開(kāi)始的內(nèi)容
Selection.HomeKey unit:=wdStory, Extend:=wdExtend
End Sub
Sub SelectToDocEnd()
'選擇從光標(biāo)至文檔結(jié)尾的內(nèi)容
Selection.EndKey unit:=wdStory, Extend:=wdExtend
End Sub
Sub SelectDocAll()
'選擇文檔全部?jī)?nèi)容(從WholeStory可猜出Story應(yīng)是當(dāng)前文檔的意思)
Selection.WholeStory
End Sub
Sub MoveToCurrentParagraphStart()
'移動(dòng)光標(biāo)至當(dāng)前段落的開(kāi)始
Selection.MoveUp unit:=wdParagraph
End Sub
Sub MoveToCurrentParagraphEnd()
'移動(dòng)光標(biāo)至當(dāng)前段落的結(jié)尾
Selection.MoveDown unit:=wdParagraph
End Sub
Sub SelectToCurrentParagraphStart()
'選擇從光標(biāo)至當(dāng)前段落開(kāi)始的內(nèi)容
Selection.MoveUp unit:=wdParagraph, Extend:=wdExtend
End Sub
Sub SelectToCurrentParagraphEnd()
'選擇從光標(biāo)至當(dāng)前段落結(jié)尾的內(nèi)容
Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
End Sub
Sub SelectCurrentParagraph()
'選擇光標(biāo)所在段落的內(nèi)容
Selection.MoveUp unit:=wdParagraph
Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
End Sub
Sub DisplaySelectionStartAndEnd()
'顯示選擇區(qū)的開(kāi)始與結(jié)束的位置,注意:文檔第1個(gè)字符的位置是0
MsgBox ("第" & Selection.Start & "個(gè)字符至第" & Selection.End & "個(gè)字符")
End Sub
Sub DeleteCurrentLine()
'刪除當(dāng)前行
Selection.HomeKey unit:=wdLine
Selection.EndKey unit:=wdLine, Extend:=wdExtend
Selection.Delete
End Sub
Sub DeleteCurrentParagraph()
'刪除當(dāng)前段落
Selection.MoveUp unit:=wdParagraph
Selection.MoveDown unit:=wdParagraph, Extend:=wdExtend
Selection.Delete
End Sub