• VBA to delete files (Word 2003)

    Author
    Topic
    #444371

    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 ( 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

    Viewing 0 reply threads
    Author
    Replies
    • #1074622

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

      • #1074943

        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 ?

        • #1074945

          Posted too soon – just found the answer …. easy as

          .SearchSubFolders = True

          Thanks again.

    Viewing 0 reply threads
    Reply To: VBA to delete files (Word 2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: