Solved

Line added to pasted richtext in Word using VB

Posted on 2006-10-22
3
498 Views
Last Modified: 2010-08-05
I have a VB application that builds a report in Word. The program grabs text from a database and pastes it into a Word bookmark. The text is richtext in nature. It all works like a charm except when it is pasted into Word it adds a line, not sure if it is a carriage return or line feed or what, but the results is that an extra line is always added. Here is the code that does the grabbing and the putting...

            Case Is = "Memo"
               
                frmMain.Controls(MyMemoField).SelStart = 0
                frmMain.Controls(MyMemoField).SelLength = Len(frmMain.Controls(MyMemoField).TextRTF)
               
                Clipboard.Clear
                Clipboard.SetText frmMain.Controls(MyMemoField).SelRTF, vbCFRTF
               
                mobjOdocument.Bookmarks(MyBookMark).Range.Select
               
                With mobjOdocument.Application.selection
                    .PasteAndFormat (wdPasteDefault)
                End With

That little extra line is messing up a realy nice report otherwise. Any ideas on where it is coming from or how to get rid of it would be greatly appreciated.
0
Comment
Question by:glenn_grubb
  • 2
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17786654
you might try this:

 Case Is = "Memo"
               
                frmMain.Controls(MyMemoField).SelStart = 0
                frmMain.Controls(MyMemoField).SelLength = Len(frmMain.Controls(MyMemoField).TextRTF)-2
               
                Clipboard.Clear
                Clipboard.SetText frmMain.Controls(MyMemoField).SelRTF, vbCFRTF
               
                mobjOdocument.Bookmarks(MyBookMark).Range.Select
               
                With mobjOdocument.Application.selection
                    .PasteAndFormat (wdPasteDefault)
                End With

or really check if the last character of the richtext is a carriage return/line feed, and only remove that from the richtext..
0
 

Author Comment

by:glenn_grubb
ID: 17786904
I solved the problem myself. Shoot!, I should have been more generous with the points!

I went to Word and recorded a macro that did what I was hoping to do. basically go to the cell where the Richtext was pasted and move to the end of the cell and hit the backspace key. I copied some of that macro and pasted it into my VB program and with a little of trial and error found that this change to my code will achieve waht i was looking for:

                With mobjOdocument.Application.Selection
                    .PasteAndFormat (wdPasteDefault)
                    .TypeBackspace 'to remove extra line feed
                End With

I added the snippet  .TypeBackspace 'to remove extra line feed to my original code and it worked.

Glenn
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 0 total points
ID: 17786918
Good work.
Question PAQed.

angelIII, page editor
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Like many others, we try and discourage users from printing documents unnecessarily and instead send or share them electronically. However, this doesn't always work and documents are still printed. With this simple solution, if the user tries to …
Shortcuts in Word Just the other day I had a training for Microsoft and they wanted me to show how well the new Windows and Office behaved on a touch device, which by the way is great, but it was only then that I realized that using keyboard shortc…
This video shows where to find the word count, how to display it, and what it breaks down to in Microsoft Word.
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now