PDA

View Full Version : Remove excess linebreaks



ghosts67
03-20-2009, 04:14 AM
I'm making a word document with the help of bookmarks and "InsertFile". But when I use insertfile, it creates some extra linebreaks in the bottom of the document. How can I trim off excess linebreaks, so I have a maxiumum of 1 through access VBA.

orange
03-20-2009, 05:56 AM
I'm making a word document with the help of bookmarks and "InsertFile". But when I use insertfile, it creates some extra linebreaks in the bottom of the document. How can I trim off excess linebreaks, so I have a maxiumum of 1 through access VBA.
You can use the Replace function. Line breaks will be the combination of
vbCrLf (Carriage return and line feed)

I would suggest that you Replace 2 vbCrLf with 1 vb CrLf

For example where y represents your text
y = Replace(y, vbCrLf & vbCrLf, vbCrLf)

If you put this is a loop, it will do the replacement recursively.

For i = 1 to 10
y = Replace(y, vbCrLf & vbCrLf, vbCrLf)
next i

At this point the multiple VBCrLf's will be reduced to a single instance.

If 10 isn't sufficient, try 20. But this process will work.

Good luck.