View Single Post
  #6   Report Post  
Posted to microsoft.public.word.formatting.longdocs
[email protected] steve.breslin@gmail.com is offline
external usenet poster
 
Posts: 7
Default inserting filenames in concatenate-files macro

A little borrowing from other posts on this newsgroup, plus a little
trial and error, and I hacked together something that works. It's
probably not the correct way to do it, but I've copied it below in
case people are interested. Thanks Doug for the help!

By the way, what's the best way to become competent with this kind of
stuff for Word and Excel? Is one of the books I've seen considered
better than the rest? Or is there a particularly good in-depth online
tutorial?

Sub combiner()
'
' combiner Macro
' Macro created 3/3/2008 by breslin
'
Dim DestDoc As Document
Dim oRg As Range
Dim MyPath As String
Dim MyName As String

'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() -1 Then Exit Sub
MyPath = .Directory
End With

'strip quotation marks from path

If Len(MyPath) = 0 Then Exit Sub

If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If

Set DestDoc = Documents.Add
DestDoc.Save ' pop up SaveAs dialog

Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd

'get files from the selected path
'and insert them into the doc
MyName = Dir$(MyPath & "*.doc")
Do While MyName ""
On Error Resume Next
oRg.InsertFile FileName:=MyPath & MyName, _
ConfirmConversions:=False, Link:=False
oRg.InsertAfter MyName & vbCr
If Err.Number = 0 Then
DestDoc.Save
Set oRg = DestDoc.Range
oRg.Collapse wdCollapseEnd
End If
MyName = Dir
Loop

End Sub