Running Macros in Word

N

Nick Hanning

I have many 1000s of documents which I want to open, find and delete
pictures, save, close and move on to the next. The documents are
stored in History files organised into folders so the macro needs to
locate all files within these subfolders.

This is all fine in principle. Via various sources etc. I have created
a macro which checks for Shapes (including first converting any which
are InlineShapes), selects and then deletes these.

I have then inserted this into the publicly available code for finding
all files within a folder (including subfolders) [special thanks to
the MS folks for that!].

Problem is that the Shapes macro works fine on single documents but,
for some reason, when it is operating within the file find loop, it
crashes at the Convert from Inline stage and closes Word altogether. I
assumed maybe it was a resources type issue so have tried limiting the
scope of the search by running on only a few folders at a time (there
are actually 2 main folders each of which has 1000 subfolders) and
then to running on 1 folder at a time (each folder has up to 1000
documents). None of this seems to work.

If the document is open and I run the Shapes bit on its own, it works
fine.

If I run the file search and open macro, then the same command causes
the system to fall over.

Does anyone have any bright ideas at all?

For reference the Shapes part of the code is:

If ActiveDocument.InlineShapes.Count > 0 Then

For Each iShape In ActiveDocument.InlineShapes
iShape.ConvertToShape
Next iShape

End If

If ActiveDocument.Shapes.Count > 0 Then

ActiveDocument.Shapes.SelectAll
Selection.Delete

End If
 
J

Jean-Guy Marcil

Bonjour,

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

|| I have many 1000s of documents which I want to open, find and delete
|| pictures, save, close and move on to the next. The documents are
|| stored in History files organised into folders so the macro needs to
|| locate all files within these subfolders.
||
|| This is all fine in principle. Via various sources etc. I have created
|| a macro which checks for Shapes (including first converting any which
|| are InlineShapes), selects and then deletes these.
||
|| I have then inserted this into the publicly available code for finding
|| all files within a folder (including subfolders) [special thanks to
|| the MS folks for that!].
||
|| Problem is that the Shapes macro works fine on single documents but,
|| for some reason, when it is operating within the file find loop, it
|| crashes at the Convert from Inline stage and closes Word altogether. I
|| assumed maybe it was a resources type issue so have tried limiting the
|| scope of the search by running on only a few folders at a time (there
|| are actually 2 main folders each of which has 1000 subfolders) and
|| then to running on 1 folder at a time (each folder has up to 1000
|| documents). None of this seems to work.
||
|| If the document is open and I run the Shapes bit on its own, it works
|| fine.
||
|| If I run the file search and open macro, then the same command causes
|| the system to fall over.
||
|| Does anyone have any bright ideas at all?
||
|| For reference the Shapes part of the code is:
||
|| If ActiveDocument.InlineShapes.Count > 0 Then
||
|| For Each iShape In ActiveDocument.InlineShapes
|| iShape.ConvertToShape
|| Next iShape
||
|| End If
||
|| If ActiveDocument.Shapes.Count > 0 Then
||
|| ActiveDocument.Shapes.SelectAll
|| Selection.Delete
||
|| End If

Why are you converting the inline shapes to floating shapes?
You stated that your goal was to delete the shapes... Why not use
ActiveDocument.InlineShapes(1).Delete

I mean, you are already iterating the InlineShapes collection; so, you
could:
'_______________________________________
With ActiveDocument
If .InlineShapes.Count > 0 Then
For i = .InlineShapes.Count To 1 Step -1
.InlineShapes(i).Delete
Next iShape
End If
End With
'_______________________________________

No?


If you still really want to convert them, have you tried with an

Application.ScreenUpdating = False

at the beginning of the code
and

Application.ScreenRefresh
Application.ScreenUpdating = False

at the end?

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

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