?
Solved

Line added to pasted richtext in Word using VB

Posted on 2006-10-22
3
Medium Priority
?
505 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
Ever visit a website where you spotted a really cool looking Font, yet couldn't figure out which font family it belonged to, or how to get a copy of it for your own use? This article explains the process of doing exactly that, as well as showing how…
This video walks the viewer through the process of creating envelopes and labels, with multiple names and addresses. Navigate to the “Start Mail Merge” button in the Mailings tab: Follow the step-by-step process until asked to find the address doc…
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…
Suggested Courses

752 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