VBA for Word 2003 - I want to delete a line break that appears

VBA for Word 2003 - I want to delete a line break that appears

Post by spenningza » Wed, 25 Feb 2009 21:06:58


I have a template Word VBA 2003. This template consist of many
bookmarks consisting of a paragraph text. If a bookmark is not
selected the paragraph should be deleted. Up to this point everything
is OK, but when the paragraph is deleted an extra line break appears.
As a result of this, if many bookmarks are not selected I get a lot of
spaces in the text. Does anybody know how to code this. I would be
very greatful for any help.
I have tried selection.backspace after paragraph.delete, but did not
work.

My code is:
If Opt2_5_Ja = Value Then
ActiveDocument.Bookmarks("bm2_5_2").Select
Paragraph.TypeParagraph
Else
ActiveDocument.Bookmarks("bm2_5_2").Delete
Selection.TypeBackspace
End If

Thanks. Karin
 
 
 

VBA for Word 2003 - I want to delete a line break that appears

Post by Graham May » Wed, 25 Feb 2009 21:29:00

I personally prefer to add stuff into a document/form as required rather
than delete it when not, so you might find
http://www.yqcomputer.com/ , however if what you are trying
to do is check the value of a variable Opt2_5_Ja and either insert a
paragraph after the associated bookmark when that variable equals a certain
value, or deletes it when not, then

Dim orng As Range
Opt2_5_Ja = InputBox("Enter Value", , 1)
Set orng = ActiveDocument.Bookmarks("bm2_5_2").Range
If Opt2_5_Ja = 1 Then
orng.InsertAfter vbCr
Else
orng.Delete
End If


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com
Word MVP web site http://www.yqcomputer.com/
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>