[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

VB Script Microsoft Word Table remove extra line break

Posted on 2016-08-28
6
Medium Priority
?
93 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 23

Accepted Solution

by:
crystal (strive4peace) - Microsoft MVP, Access earned 2000 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 23
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 46

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 23
ID: 41778568
thank you and you're welcome ~ happy to help
0
 
LVL 23
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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
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 Hyperlinks for the web and other documents. Select the "Insert" tab: Click "Hyperlink":  Type "http://" followed by a web address to reference a website or navigate to a document to ref…
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.
Suggested Courses

810 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