Solved

VB Script Microsoft Word Table remove extra line break

Posted on 2016-08-28
6
59 Views
Last Modified: 2016-08-31
How can I prevent the following code from adding a line

tbl.cell(row,5).range.text = replace(tbl.cell(row,5).range.text, "2017",(cfy+1))

Screenshot #1 (Table prior to script with header align at bottom):  http://www.screencast.com/t/NawU2AilNy
Screenshot #2 (Table after script with un-wanted line break disrupting the align at bottom appearance) :  http://www.screencast.com/t/R9NpAJoRm
0
Comment
Question by:maxdbase
  • 4
6 Comments
 
LVL 19

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 500 total points
ID: 41773739
Chr(10) = line-feed
chr(13) = carriage-return

not sure if Word uses Chr(10) like Excel or Chr(13) & Chr(10) ... but you can try replacing line breaks with 1 character and then replacing 2 characters with 1 character:

either
replace(replace(Text-To-Replace, chr(10), " "),"  "," ")

Open in new window

or
replace(replace(Text-To-Replace, chr(13) & chr(10), " "),"  "," ")

Open in new window

0
 

Author Comment

by:maxdbase
ID: 41773771
Wow, it worked,

http://www.screencast.com/t/ydKYV0xB

I slightly modified the example as follows

tbl.cell(row,c).Range.Text = replace(replace(tbl.cell(row,c).Range.Text, chr(10) , " "),"  "," ")
                              tbl.cell(row,c).Range.Text = replace(replace(tbl.cell(row,c).Range.Text, chr(13) , " "),"  "," ")

You're the best!!!
0
 
LVL 19
ID: 41773777
you're welcome ~ happy to help ... and thanks for sharing what you did. btw, if you are going to do multiple operations with the same object, it helps readability and performance to use WITH
with tbl.cell(row,c).Range
   .text = replace(replace(.Text, chr(10) , " "),"  "," ")
   .text = "blah blah"
end with 

Open in new window

0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 45

Expert Comment

by:aikimark
ID: 41775324
You might use vbCr, vbLF, and vbCrLf intrinsic constants in place of the Chr() functions.  This will make your code a bit easier to read/understand/maintain and be faster performer if you have a lot of data.

If you do have a lot of data and fast performance is a necessity, you might try invoking the Replace() functions against an array.  The transfer of data can take place in one from and one to operation (per area).  An example of this can be found in this article:
https://www.experts-exchange.com/articles/2253/Fast-Data-Push-to-Excel.html
0
 
LVL 19
ID: 41778568
thank you and you're welcome ~ happy to help
0
 
LVL 19
ID: 41778581
please also note aikimark's message with the constant names. When helping others, I like to explain what they are since you cannot always use constants (ie: in Access queries)
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

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 article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
This Micro Tutorial well show you how to find and replace special characters in Microsoft Word. This is similar to carriage returns to convert columns of values from Microsoft Excel into comma separated lists.
Office 365 is currently available in five editions. Three of them are for business use: Office 365 Business Essentials, Office 365 Business, and Office 365 Business Premium. Two of them are for home/personal use: Office 365 Home and Office 365 Perso…

777 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