finding markups in a word document

G

gary

Hi,

I'd like use vba to modify an existing document
so that only those pages that contain markups
are saved (i.e. remove all pages that don't contain
markup)

Any help would be much appreciated.

I'm using the word 2003 object model

Thanks
 
D

DA

Hi Gary

Problem with working with pages is that they are never
static or classed as objects. Your best bet is probably
to section your document into pages, even if you have to
write another macro to do that. This way you can at least
target the sections (pages) that have markup and delete
them.

For example:

Dim mySection As Section
For Each mySection In ActiveDocument.Sections
If mySection.Range.Revisions.Count > 0 Then
mySection.Range.Delete
End If
Next mySection

Hope that helps,
Dennis
 
J

Jean-Guy Marcil

Bonjour,

Dans son message, < gary > écrivait :
In this message, < gary > wrote:

|| Hi,
||
|| I'd like use vba to modify an existing document
|| so that only those pages that contain markups
|| are saved (i.e. remove all pages that don't contain
|| markup)
||
|| Any help would be much appreciated.
||
|| I'm using the word 2003 object model
||

If by markup you mean revisions, try this code.
Note that at the beginning of the code I have to turn off track changes
otherwise the act of deleting a page will add a revision mark...

'_______________________________________
Dim PageRge As Range

Application.ScreenUpdating = False
ActiveDocument.TrackRevisions = False

With Selection
.HomeKey wdStory

Do While .Start < ActiveDocument.Range.End - 1
Set PageRge = .Bookmarks("\Page").Range
With PageRge
If .Revisions.Count > 0 Then
.Select
Selection.Collapse wdCollapseEnd
Else
.Delete
End If
End With
Loop

End With

Application.ScreenRefresh
Application.ScreenUpdating = True
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 
G

gary

Hope that helps

Thanks for the quick reply, just what I was looking for
Dim mySection As Section
For Each mySection In ActiveDocument.Sections
If mySection.Range.Revisions.Count > 0 Then
mySection.Range.Delete
End If
Next mySection

pretty much used this code as is. Only tweak
was interating through sections from document end to
to beginning to save processor time (as a lot of sections
end up being deleted).
Problem with working with pages is that they are never
static or classed as objects. Your best bet is probably
to section your document into pages, even if you have to
write another macro to do that. This way you can at least
target the sections (pages) that have markup and delete
them.

Good advice - I mapped sections=pages

-Gary
 
G

gary

Hope that helps

Thanks for the quick reply, just what I was looking for
Dim mySection As Section
For Each mySection In ActiveDocument.Sections
If mySection.Range.Revisions.Count > 0 Then
mySection.Range.Delete
End If
Next mySection

pretty much used this code as is. Only tweak
was interating through sections from document end to
to beginning to save processor time (as a lot of sections
end up being deleted).
Problem with working with pages is that they are never
static or classed as objects. Your best bet is probably
to section your document into pages, even if you have to
write another macro to do that. This way you can at least
target the sections (pages) that have markup and delete
them.

Good advice - I mapped sections=pages

-Gary
 

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