实现环境:Visual Studio 2010, VSTO 4.0, Office 2010.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Word = Microsoft.Office.Interop.Word;
namespace WordInsertStringBeforeCursor
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Word.Application objApplication = Globals.ThisDocument.Application;
Word.Selection objSelection = objApplication.Selection;
Word.Range objRange = objSelection.Range;
objRange.InsertAfter("Test");
objRange.Collapse(Word.WdCollapseDirection.wdCollapseEnd);
objRange.Select();
}
}
}
相关下载:http://download.csdn.net/detail/tx_officedev/3862842
欢迎访问我的主博客《许阳的红泥屋》