使用WORD来键入和编辑程序,则应该注意什么问题?

来源:百度知道 编辑:UC知道 时间:2024/06/02 09:31:53

http://www.officexy.com/Articles/Word/WordVBA/

Word编程中的一些基本操作

1. 选择范围:
//选择整个文档
ThisDocument.Content.Select();
wapp.Selection.TypeText("Good good study!");

object count = 20;
object start = 0; //所选范围的起始位置
object end = 0; //所选范围的结束位置
Word.Range rn = adoc.Range(ref start, ref end);
rn.Text = "Good Study"; //如果开始位置和结束位置相同,就是选择了一个插入点,可以插入文本
object unit = Word.WdUnits.wdCharacter;
rn.MoveEnd(ref unit, ref count); //扩展选择范围
rn.SetRange(ref start,ref count); //重新设置选择范围

//选择整个文档 :
object endLocation = ThisDocument.Content.End;
object startLocation = ThisDocument.Content.Start;
Word.Range rng = ThisDocument.Range(ref startLocation, ref endLocation);
rng.Select()