Programatically concatenating Word files

S

Scott Bass

Hi,

I received the following reply in microsoft.public.word.newusers. I was
hoping someone here could help me in modifying this macro:

http://vbaexpress.com/kb/getarticle.php?kb_id=214

I need to change the macro to display a File Selection dialog (which
supports wildcards), rather than the Folder Selection dialog.

Regards,
Scott
 
A

Al Borges

Hi Scott:

Your wanting to apply a certain order to your selections makes the
process/code somewhat longer. I had to take your code and mix it with one
that I have for a hyperlink form in which I dump the name and path for each
record into a temporary table from which you could then use as a recordset
to manipulate- i.e. apply an order. The hyperlink form from which my code
came from can be found in http://briefcase.yahoo.com/alborgmd, go to the "MS
Access Files" then download the "Use of Hyperlinks Form".

----------------------------------------------------------------------

With Application
.DisplayAlerts = False
.ScreenUpdating = Flase
With .filesearch
.NewSearch
.LookIn = Dir(Path & "\", vbNormal)
.FileName = *.doc
. SearchSubFolders = False
End With
.FileSearch
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("WordDocuments", dbOpenDynaset)
With rst
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
.AddNew
![Link] = .FoundFiles(i)
' the ![Link] entry will look like this: "C:\Office
Documents\AllportoAdmission.doc"
'![DocName] = Dir(rst![Link]) ' the
![DocName] will look like this: "AllportoAdmission.doc"-----> this line can
be removed
'![PathDate] = FileDateTime(rst![Link]) ' the
![PathDate] will look like this: "12/7/2001 8:17:46 AM" -----> this line can
be removed
.UPDATE
Next i
Else
MsgBox "There were no files found."
End If
End With
' now set the sort order that you wish
Set rst = dbs.OpenRecordset(Select WordDocuments.* from WordDocuments ORDER
BY WordDocuments.DocName; ", dbOpenDynaset)
' now begin attaching the files
With rst
For i = 1 To .Count
Application.Selection.InsertFile FileName:=![Link]
.InsertParagraphAfter
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse Direction:=wdCollapseEnd
Next i
End With

The above code seems logical and like it should work for you. Please let me
know if you have any problems with it.

Regards,
AL
 
J

J Lenihan

I have another wrinkle for this. This is great for combining files and I am
constantly doing that, however, to get the files in order I have t rename
them 01,02,03, ect to get them to concaninate in order. I know some vba but I
am wondering if anyone has done or can guide me to have a dialog box where I
can select the files to concatinate, select them, and then arrange the order
before they are combined?

Thanks alot

Jerry

Al Borges said:
Hi Scott:

Your wanting to apply a certain order to your selections makes the
process/code somewhat longer. I had to take your code and mix it with one
that I have for a hyperlink form in which I dump the name and path for each
record into a temporary table from which you could then use as a recordset
to manipulate- i.e. apply an order. The hyperlink form from which my code
came from can be found in http://briefcase.yahoo.com/alborgmd, go to the "MS
Access Files" then download the "Use of Hyperlinks Form".

----------------------------------------------------------------------

With Application
.DisplayAlerts = False
.ScreenUpdating = Flase
With .filesearch
.NewSearch
.LookIn = Dir(Path & "\", vbNormal)
.FileName = *.doc
. SearchSubFolders = False
End With
.FileSearch
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("WordDocuments", dbOpenDynaset)
With rst
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & " file(s) found."
For i = 1 To .FoundFiles.Count
.AddNew
![Link] = .FoundFiles(i)
' the ![Link] entry will look like this: "C:\Office
Documents\AllportoAdmission.doc"
'![DocName] = Dir(rst![Link]) ' the
![DocName] will look like this: "AllportoAdmission.doc"-----> this line can
be removed
'![PathDate] = FileDateTime(rst![Link]) ' the
![PathDate] will look like this: "12/7/2001 8:17:46 AM" -----> this line can
be removed
.UPDATE
Next i
Else
MsgBox "There were no files found."
End If
End With
' now set the sort order that you wish
Set rst = dbs.OpenRecordset(Select WordDocuments.* from WordDocuments ORDER
BY WordDocuments.DocName; ", dbOpenDynaset)
' now begin attaching the files
With rst
For i = 1 To .Count
Application.Selection.InsertFile FileName:=![Link]
.InsertParagraphAfter
.InsertBreak Type:=wdSectionBreakNextPage
.Collapse Direction:=wdCollapseEnd
Next i
End With

The above code seems logical and like it should work for you. Please let me
know if you have any problems with it.

Regards,
AL

Scott Bass said:
Hi,

I received the following reply in microsoft.public.word.newusers. I was
hoping someone here could help me in modifying this macro:

http://vbaexpress.com/kb/getarticle.php?kb_id=214

I need to change the macro to display a File Selection dialog (which
supports wildcards), rather than the Folder Selection dialog.

Regards,
Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top