weird problem deleting a line

M

Mark Kurten

In my word doc I have a sentence.

Ex.



This is a sentence to illustrate my problem. This line has a paragraph

marker after it.¶



Here is the code i use to delete lines.



APPWORD.ActiveDocument.Bookmarks(strBM).Range.Select
APPWORD.Selection.Delete
APPWORD.Selection.GoTo What:=wdGoToBookmark, Name:="\Line"
Length = Len(APPWORD.Selection)

If Length = 1 Then
APPWORD.Selection.Delete Unit:=wdCharacter, Count:=1
End If



This works great when I have the visible property set to true. Ex.
SomeWordDocument.Visible = true



When i set the visible property to false, the bookmark gets deleted but the
line doesn't get deleted.



Makes no sense to me. When the visible property is false, i have 2 blank
lines in between these paragraphs when I only should have 1.



Thanks in advance for any insight.
 
A

Andrew Savikas

Hi Mark

It's a little hard to tell from your code exactly what you're trying to do, but it appears that you want to find the bookmark strBM, delete it and any text that it "contains", and then test to see if what's left is a blank paragraph. If so, you want that paragraph deleted

I'm not positive, but I don't think the selection object works well with visible set to false (sort of makes sense, though). Instead use the Paragraph and Range objects (this assumes that the bookmark won't span paragraphs -- you could certainly adapt it to handle that as well)

Dim rng As Rang
Dim para As Paragrap
Set rng = ActiveDocument.Bookmarks(strBM).Rang
Set para = rng.Paragraphs(1
rng.Delet
If para.Range.Characters.Count = 1 The
para.Range.Delet
End I


HTH
Andrew Savika

----- Mark Kurten wrote: ----

In my word doc I have a sentence

Ex



This is a sentence to illustrate my problem. This line has a paragrap

marker after it.Â



Here is the code i use to delete lines



APPWORD.ActiveDocument.Bookmarks(strBM).Range.Selec
APPWORD.Selection.Delet
APPWORD.Selection.GoTo What:=wdGoToBookmark, Name:="\Line
Length = Len(APPWORD.Selection

If Length = 1 The
APPWORD.Selection.Delete Unit:=wdCharacter, Count:=
End I



This works great when I have the visible property set to true. Ex
SomeWordDocument.Visible = tru



When i set the visible property to false, the bookmark gets deleted but th
line doesn't get deleted



Makes no sense to me. When the visible property is false, i have 2 blan
lines in between these paragraphs when I only should have 1



Thanks in advance for any insight
 
M

mark kurten

You described exactly what i want to do...

Let's say i had Example:

Some sentence with a [bookmark] in it.

Now, let's say I wanted to just delete the [bookmark] in the sentence above.
Would your code handle this condition as well? It appears it will. I'm not
real familiar with the paragraph object.

Thanks for the help.


A sentend
Andrew Savikas said:
Hi Mark,

It's a little hard to tell from your code exactly what you're trying to
do, but it appears that you want to find the bookmark strBM, delete it and
any text that it "contains", and then test to see if what's left is a blank
paragraph. If so, you want that paragraph deleted.
I'm not positive, but I don't think the selection object works well with
visible set to false (sort of makes sense, though). Instead use the
Paragraph and Range objects (this assumes that the bookmark won't span
paragraphs -- you could certainly adapt it to handle that as well):
 
M

Mark Kurten

your example works great with one exception I've found.

I have a table in my document with 4 rows

in each row i have the following example data:

Row 1 Data.¶
Row 2 Data.¶
Row 3 Data .¶
Row 4 Data (on this row only i have a tab character after the word Data, i
can't put a .¶
because i'm at the bottom of the page and putting a .¶
would make it go to the second page)

Your example deletes the first three rows fine, but on the fourth row i get
an error that states "Cannot edit range"
This error is generated with the line --- para.Range.Delete

I assume that is because it's in a table?


Andrew Savikas said:
Hi Mark,

It's a little hard to tell from your code exactly what you're trying to
do, but it appears that you want to find the bookmark strBM, delete it and
any text that it "contains", and then test to see if what's left is a blank
paragraph. If so, you want that paragraph deleted.
I'm not positive, but I don't think the selection object works well with
visible set to false (sort of makes sense, though). Instead use the
Paragraph and Range objects (this assumes that the bookmark won't span
paragraphs -- you could certainly adapt it to handle that as well):
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top