Can't edit range

A

Alexander Mueller

Hi @ all

i want to copy a document and then remove some parts of it.

I do the copy with WordBasic.CopyFileA, since VBA.FileCopy
fails on opened docs.
After having copied the file, I open it using
Documents.Open in invisible manner.

Then I want to remove the first part of the document , from the
very beginning to one char before a certain bookmark

I use the following code

Set oRng = oNewDoc.Range(0, oNewDoc.Bookmark("bmname").Start - 1)
oRng.Delete


However i get error 5904, "Cannot edit range" on the delete statement

What may be the reason for this?

Strangely it worked until I changed the bookmark "bmname" from being
a 1 char-bookmark to one that extends over a table and a pagebreak.
But the range to delete doesn't overlap with this bookmark's range,
so i wonder why there seems to be an interference.

Any hints much appreciated!

TIA & bye,
Alex
 
A

Alexander Mueller

David said:
Change Bookmark to Bookmarks

sorry
that was an error only in the posted code
didn't c&p it. It's bookmarks in the project.

MfG,
Alex
 
D

David Sisson

I made a sample doc just as you described and it work perfectly.

Post the original code.
 
K

Klaus Linke

Hi Alexander,

Have you checked whether the range you're trying to delete contains a
paragraph mark right in front of a table?

Klaus
 
A

Alexander Mueller

Klaus said:
Hi Alexander,

Have you checked whether the range you're trying to delete contains a
paragraph mark right in front of a table?

Klaus


Hi Klaus and David

Thanks for your hints and support.
The reason was, that the last chaarcter of the range to delete was
a paragraph-mark directly following a table. So Klaus was right with
his assumption! After adding an additional dummy-paragraph it works
as desired.

MfG,
Alex
 

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