Solved

Line added to pasted richtext in Word using VB

Posted on 2006-10-22
3
503 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Nice table. Huge mess. Maybe this was something you created way back before you figured out tabs or a document you received from someone else. Either way, using the spacebar to separate the columns resulted in a mess. Trying to convert text to t…
I would like to show you some basics you can do with Mailings in MS Word. It´s quite handy feature you can use for creating envelopes, labels, personalized letters etc. First question could be what is this feature good for? Mailing can really he…
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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