Consulting

Results 1 to 3 of 3

Thread: Insert All Documents into One

  1. #1
    Site Admin
    The Princess
    VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location

    Insert All Documents into One

    I need a sub to insert all files from *this* directory into *this document*.

    So, all my files are in a directory.
    I create a new file.
    I put your sub in it.
    I save it in the SAME directory.

    I run the code.
    This document gets all the other docs inserted into it using Insert-File, and in no particular order.

    Thanks!!
    ~Anne Troy

  2. #2
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Hi Dreamboat,
    The below macro will insert all doc's in the docdirectory into the current doc. If you require more help let me know. If this does not work as required let me know.
    [VBA]
    Sub Macro1()
    Dim DocDir As String
    Dim LookFor As String
    Dim FileName As String
    DocDir = "c:\my documents\" '<--the directory to look in
    LookFor = "*.doc"
    FileName = Dir(DocDir & LookFor)
    While FileName <> vbNullString
    Selection.InsertFile FileName:=FileName, Range:="", ConfirmConversions:= _
    False, Link:=False, Attachment:=False
    FileName = Dir
    Wend
    ActiveDocument.SaveAs DocDir & "newfilename.doc" '<-- change this to a valid filename
    End Sub

    [/VBA]
    Happy Coding
    Tommy

  3. #3
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    Cool! I'll send it to the user.
    ~Anne Troy

Posting Permissions

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