Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA to delete files (Word 2003)

    Many thanks in anticipation of your help. I have the following code to interrogate a directory and provide a report of those documents which are empty. Ideally I'd like these documents to be deleted - the code so far just produces a report of those documents which are empty. Can anyone enlighten me on a code fix to either (a) delete the empty document or ([img]/forums/images/smilies/cool.gif[/img] copy the empty document to another folder.

    Dim CountedSet As CountedSet
    Dim sString As String
    Dim vFileName As Variant

    Set CountedSet = New CountedSet

    Documents.Add Template:="Normal", NewTemplate:=False, DocumentType:=0

    With Application.FileSearch
    .FileName = "*.*"
    .LookIn = "i:Test"
    .Execute
    End With

    For Each vFileName In Application.FileSearch.FoundFiles

    Application.Documents.Open vFileName

    Set myRange = ActiveDocument.Range

    If ActiveDocument.Content.StoryLength = 1 Then
    sString = vFileName
    CountedSet.Add sString
    End If

    ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges

    Next vFileName

    CountedSet.Report

  2. #2
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Wellington, New Zealand
    Posts
    143
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: VBA to delete files (Word 2003)

    You might be able to use the Kill statement to do (a). Its use is explained here .

  3. #3
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to delete files (Word 2003)

    That's it - very obvious I would say, but not a statement I knew about - Thanks so much William. Now another little snag - How do I also cycle through the documents in any sub-folders as well ?

  4. #4
    Lounger
    Join Date
    Mar 2001
    Location
    NSW, Australia
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA to delete files (Word 2003)

    Posted too soon - just found the answer .... easy as

    .SearchSubFolders = True

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •