How to use this DeleteEMFs() Macro

G

giorgio

This macro was on the MicroSoft website as a work around for the .emf
storage problem

http://support.microsoft.com/default.aspx?scid=kb;en-us;299372

What exactly does this macro do and how should I use it? I want to
remove all the .emf files from a particular Excel File. B/c the
workbook creates hundreds or thousands of temp .emf files everytime it
opens and it takes forever to open..

Thank you very much for any help!

george

Private Sub Workbook_Open()
Call DeleteEMFs
End Sub


Private Sub DeleteEMFs()
Dim fso As Variant
Set fso = CreateObject("Scripting.FileSystemObject")
Dim fs As FileSearch
Dim i As Long
Set fs = Application.FileSearch
With fs
.LookIn = fso.GetSpecialFolder(2)
.Filename = "*.emf"

If .Execute(SortBy:=msoSortByFileName,
SortOrder:=msoSortOrderAscending) > 0 Then
On Error Resume Next
For i = 1 To .FoundFiles.Count
Kill .FoundFiles(i)
Next i
On Error GoTo 0
End If

End With

Set fso = Nothing
Set fs = Nothing
End Sub
 
D

Dave Peterson

It almost does the same thing as that script (in the previous thread).

This version has:
..LookIn = fso.GetSpecialFolder(2)
(2 represents the Windows Temp folder)

But this version only looks for *.emf files and deletes them.

I didn't try this, but I don't think you would want to run this from the
workbook that causes the trouble. The workbook is already open by the time the
workbook_open event fires.

But you could change it slightly so that it cleans the temp folder, opens your
file, and closes this "cleaner" workbook:

Private Sub Workbook_Open()
Call DeleteEMFs
workbooks.open filename:="C:\yourpath\yourfile.xls"
me.close
End Sub

If you're new to macros, you may want to read David McRitchie's intro at:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

But for me, I'll continue to clean up using that .VBS script. I don't have to
start excel to run it and it cleans up more stuff (yeah, you could modify that
macro, though).
 

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