Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word
Pasting RichText into Word Pasting RichText into Word
Pasting RichText into Word
Go Back  Xtreme Visual Basic Talk > > > Pasting RichText into Word


Reply
 
Thread Tools Display Modes
  #1  
Old 02-28-2005, 03:06 PM
mav0707 mav0707 is offline
Newcomer
 
Join Date: Feb 2005
Posts: 6
Angry Pasting RichText into Word


I'm trying to paste the contents of a RichTextBox(from a vb.net application) into Word for a spelling/grammar check. The richtext may have various formatting so I need to be able to copy and paste the text between my vb app and word without loosing formatting. I currently can send the text to word but only a portion of the formatting is staying. Here's a copy of my procedure. I appreciate any suggestions!
Code:
Try ' Create Word and temporary document objects. Dim objWord As Object Dim objTempDoc As Object Dim iData As IDataObject Dim data As New DataObject If rtbCC.Text = "" Then Exit Sub End If objWord = New Word.Application objTempDoc = objWord.Documents.Add objWord.Visible = False ' Position Word off the screen...this keeps Word invisible ' throughout. objWord.WindowState = 0 objWord.Top = -3000 data.SetData(DataFormats.Rtf, rtbCC.Rtf) Clipboard.SetDataObject(data) With objTempDoc .Content.Paste() .Activate() .CheckSpelling() .CheckGrammar() .Content.Copy() iData = Clipboard.GetDataObject If iData.GetDataPresent(DataFormats.Rtf, False) Then rtbCC.Text = iData.GetData(DataFormats.Text, True).ToString() End If .Saved = True .Close() End With If Not objWord Is Nothing Then Dim SaveNoChanges As Object SaveNoChanges = Word.WdSaveOptions.wdDoNotSaveChanges objWord.Quit(SaveNoChanges, Nothing, Nothing) End If MessageBox.Show("The spelling/grammar check is complete.", _ "Spell/Grammar Checker", MessageBoxButtons.OK, _ MessageBoxIcon.Information) ' Microsoft Word must be installed. Catch Ex As COMException MessageBox.Show("Microsoft Word must be installed for Spell/Grammar Check " & _ "to run.", "Spell/Grammar Checker") Catch Excep As Exception MessageBox.Show("An error has occured. Error = " & Excep.Message, "Spell/Grammar Checker") End Try

Last edited by herilane; 03-01-2005 at 05:10 PM. Reason: [vb] tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word Pasting RichText into Word
Pasting RichText into Word
Pasting RichText into Word
 
Pasting RichText into Word
Pasting RichText into Word
 
-->