G
Gordon Bentley-Mix
I have used variations of the following code snippets in several templates.
Sub DeleteMe()
If ActiveDocument.Bookmarks.Exists("DeleteMe") Then
ActiveDocument.Bookmarks("DeleteMe").Range.Delete
End Sub
Sub DeleteMyStyleParas()
Dim myPara As Paragraph
For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = "myStyle" Then myPara.Range.Delete
Next myPara
End Sub
Without going into a great deal of detail, the basic idea behind this code
is to clean up a document after running a UserForm. The first deletes a bit
of the content surrounded by a bookmark, and the second removes all the
paragraphs of a certain style. Most of the time it works flawlessly, but in a
couple of templates I've notices some problems.
First, 'DeleteMe' doesn't delete correctly if the bookmark contains a table
(sometimes - see end of this paragraph). The content of the table is deleted
- although sometimes the formfields in the table remain - but the table
itself is left. This happens even if the bookmark includes the paragraph
before the table, which is the only way it works in the other templates where
it does work. And if it includes the paragraph after the table as well, it
deletes the table but leaves the leading and trailing paragraphs and the
bookmark behind. It does work if I select the bookmark range first and then
delete the selection, but I'm trying to get away from using the Selection
object as much as possible. And it works fine in the same template if the
bookmark only contains text or formfields (and in a couple of notable cases,
even when the bookmark contains a table - GAHHH!).
Second, 'DeleteMyStyleParas' doesn't delete either - at all. The paragraphs
with a style of 'MyStyle' still remain in the document. I've checked to make
sure the style name is correct and even tried using .NameLocal, but no joy.
These things happen only in the templates in which they happen and never in
those in which they don't happen. (Wow! That's convoluted, but I can't think
of a better way to explain it. ;-D) Any ideas?
--
Cheers!
Gordon
The Kiwi Koder
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.
Sub DeleteMe()
If ActiveDocument.Bookmarks.Exists("DeleteMe") Then
ActiveDocument.Bookmarks("DeleteMe").Range.Delete
End Sub
Sub DeleteMyStyleParas()
Dim myPara As Paragraph
For Each myPara In ActiveDocument.Paragraphs
If myPara.Style = "myStyle" Then myPara.Range.Delete
Next myPara
End Sub
Without going into a great deal of detail, the basic idea behind this code
is to clean up a document after running a UserForm. The first deletes a bit
of the content surrounded by a bookmark, and the second removes all the
paragraphs of a certain style. Most of the time it works flawlessly, but in a
couple of templates I've notices some problems.
First, 'DeleteMe' doesn't delete correctly if the bookmark contains a table
(sometimes - see end of this paragraph). The content of the table is deleted
- although sometimes the formfields in the table remain - but the table
itself is left. This happens even if the bookmark includes the paragraph
before the table, which is the only way it works in the other templates where
it does work. And if it includes the paragraph after the table as well, it
deletes the table but leaves the leading and trailing paragraphs and the
bookmark behind. It does work if I select the bookmark range first and then
delete the selection, but I'm trying to get away from using the Selection
object as much as possible. And it works fine in the same template if the
bookmark only contains text or formfields (and in a couple of notable cases,
even when the bookmark contains a table - GAHHH!).
Second, 'DeleteMyStyleParas' doesn't delete either - at all. The paragraphs
with a style of 'MyStyle' still remain in the document. I've checked to make
sure the style name is correct and even tried using .NameLocal, but no joy.
These things happen only in the templates in which they happen and never in
those in which they don't happen. (Wow! That's convoluted, but I can't think
of a better way to explain it. ;-D) Any ideas?
--
Cheers!
Gordon
The Kiwi Koder
Uninvited email contact will be marked as SPAM and ignored. Please post all
follow-ups to the newsgroup.