Solved

Line added to pasted richtext in Word using VB

Posted on 2006-10-22
3
501 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 143

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 143

Accepted Solution

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

angelIII, page editor
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Selection object is designed for user interaction. It has a Range property, so it can be used in most places that a Range object can. Recorded macros must use the Selection because they are simply copying what the user is doing. A Range prope…
A few years ago I was very much a beginner at VBA, and that very much remains the case today.  I'll do my best to explain things as I go in the hope that other beginners can follow.  If you just want to check out a tool that creates a Select Case fu…
This video walks the viewer through the process of creating an MLA formatted document, as well as a bibliography with citations.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

749 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