Skip to main content

Posts

Showing posts from May, 2008

VSTO - Use RichTextBox with Range

In VSTO project, we can use WinForm dialog with RichTextBox to allow user to input rich formatted text. The Rtf property of RichTextBox returns the string representing the content in Rtf format. However, there is no direct way to insert the Rtf content into Word Range object. The Text property of Range object only accept plain text and there is no Rtf property in Range object. After the long search and experiment, I found out that the only way to communicate between RichTextBox and Range object is via Clipboard. From RichTextBox to Range: Private Sub InsertRtf(ByRef strRtfMessage As String, ByRef oRange As Word.Range) With oRange.FormattedText .Style = "Body Single" Clipboard.Clear() Clipboard.SetData(DataFormats.Rtf, strRtfMessage) .Paste() End With End Sub From Range to RichTextBox: Private Function TransformRangeToRtf(ByRef oRange As Word.Range, ByRef rtfMsg As RichTextBox) As String oRange.Copy() rtbMsg...

VSTO Spelling Check - Use different dictionary

When we are using Spelling check function of Word, sometime we may need to use a different dictionary than the default one. The default dictionary is determined by default language. In Word.Application object, there is a property called Language, but it is read only and can not be changed. After some search on Google, I finally find that Word.Range object has a property called LanguageID, which you can set to change the dictionary used in spelling check. Following code snippet shows how to use different dictionary: Private Function CheckRangeSpelling(ByRef oRange As Word.Range) As Boolean ' Grab the text before spell checking Dim strText As String = oRange.Text ' Check the spelling using French Canadian dictionary oRange.NoProofing = False oRange.LanguageID = Word.WdLanguageID.wdFrenchCanadian oRange.CheckSpelling() ' Check if user has changed anything during the spell checking If strText oRange.Text Then ...