Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Apr 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    count documents in directories (word 2000)

    Hi,

    Hope you can help me, or my easter weekend is ruined. I need to perform an action on documents in a directory: open them one by one, copy a table an paste the table into an new document. I also need to get the document' s name and paste that above the tables in the new document. There are about a hundred documents in the directory. I can us e do...loop, but don't know how to count the amount of documents in the directory. Is there a command for this?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: count documents in directories (word 2000)

    Sample code in previous posts:

    Re: Properties (2002)

    Re: Combin documents into one (Word97) (Word 97 S

    Weekend saved?

  3. #3
    Lounger
    Join Date
    Jan 2006
    Posts
    31
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: count documents in directories (word 2000)

    Yes, weekend saved. Thanks a lot.

    This is the code I used (a lot of it is copied of course, and since I'm Dutch some of the variables have Dutch names.) The only strange thing is that application.screenupdating doesn't work, but that will be local, i guess. Happy easter, kiss the bunny for me.

    Sub MaakDomeingegevens()

    Application.ScreenUpdating = False
    Const strPad = "Homeingegevenscontrole"

    Dim StrBestand As String, DocOld As Document, DocNew As Document, IntTabel As Integer, strDatum As String, i As Integer

    On Error GoTo ErrHandler


    strDatum = Format(Date, "dd-mm-yyyy")
    StrBestand = Dir(strPad & "*.doc")

    Documents.Add
    ActiveDocument.SaveAs FileName:=strPad & "Obs" & strDatum & ".doc"
    Do While Not StrBestand = "" 'go on until the last one has been processed

    Set DocOld = Documents.Open(FileName:=strPad & StrBestand, AddToRecentFiles:=False) 'open documents
    IntTabel = ActiveDocument.Tables.Count 'Activate counter, to define number of tables in document (May vary)

    ActiveDocument.Tables(1).Select 'Select and copy first table
    Selection.Copy
    Documents("Obs" & strDatum & ".doc").Activate 'Alt+TAB to other document
    Selection.EndKey Unit:=wdStory, Extend:=wdMove 'go to last page
    Selection.Paste
    Selection.InsertParagraph
    Documents(StrBestand).Activate 'Alt+TAB to source document
    ActiveDocument.Tables(IntTabel).Select 'go to last table in document
    Selection.Copy
    DocOld.Close SaveChanges:=wdDoNotSaveChanges 'close doocument, other document appears
    Selection.EndKey Unit:=wdStory, Extend:=wdMove
    Selection.Paste
    Selection.InsertBreak Type:=wdPageBreak 'New page

    StrBestand = Dir 'Process next document
    Loop

    ExitHandler:
    ActiveDocument.Save
    Application.ScreenUpdating = True
    Set DocOld = Nothing
    Exit Sub

    ErrHandler:
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End Sub

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: count documents in directories (word 2000)

    Paul,

    Application.ScreenUpdating = False works only partially under the best of circumstances; in particular, Word is not able to hide opening new documents and switching between documents. If you pause a macrp or single-step through it, ScreenUpdating will usually be reset to True.

Posting Permissions

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