A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Formatting Long Documents
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

inserting filenames in concatenate-files macro



 
 
Thread Tools Display Modes
  #1  
Old March 3rd, 2008, 01:11 AM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default inserting filenames in concatenate-files macro

I have a bunch of DOC files that I need to combine into one master
file. That's no problem, but I need to include the filename before the
insertion of each file. So the master doc should look like this:

--

file1.doc

file1's contents inserted here.

file2.doc

file2's contents inserted here.

--

Please help.
  #2  
Old March 3rd, 2008, 09:36 AM posted to microsoft.public.word.formatting.longdocs
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default inserting filenames in concatenate-files macro

I assume that you are doing this manually rather than through code (because
if the code was not problem for you, the filename should not be either)

If that is the way you are doing it, insert a { FILENAME } field at the top
of each the document - Use Ctrl+F9 to insert a pair of field delimiters { }
inside of which you type FILENAME (or filename, it doesn't matter), then
press Alt+F9 to toggle off the display of field codes, then select the field
and press F9 if necessary to cause the filename to be displayed, then use
Ctrl+Shift+F9 to unlink the field. The last step will convert the field
result to ordinary text so that it will be preserved when you combine the
documents.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
...
I have a bunch of DOC files that I need to combine into one master
file. That's no problem, but I need to include the filename before the
insertion of each file. So the master doc should look like this:

--

file1.doc

file1's contents inserted here.

file2.doc

file2's contents inserted here.

--

Please help.



  #3  
Old March 3rd, 2008, 10:04 AM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default inserting filenames in concatenate-files macro

On Mar 3, 4:36 am, "Doug Robbins - Word MVP"
wrote:
I assume that you are doing this manually rather than through code (because
if the code was not problem for you, the filename should not be either)


Clumsily asked question, sorry. -- I do need to do this in the code.
(I found code to combine the material on the web, and there's a recent
discussion of this topic on this newsgroup as well. I tried to figure
out how to modify it to insert filenames, but I didn't get very far.)

I figured such an algorithm would work something like this:

open dialogue to select files to insert.
iterate over the files to insert {
1. insert filename
2. insert file
}

  #4  
Old March 3rd, 2008, 12:13 PM posted to microsoft.public.word.formatting.longdocs
Doug Robbins - Word MVP
external usenet poster
 
Posts: 8,239
Default inserting filenames in concatenate-files macro

It will be easier to tell you how to go about this if you post the code that
you already have do the insertion of the files.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

wrote in message
...
On Mar 3, 4:36 am, "Doug Robbins - Word MVP"
wrote:
I assume that you are doing this manually rather than through code
(because
if the code was not problem for you, the filename should not be either)


Clumsily asked question, sorry. -- I do need to do this in the code.
(I found code to combine the material on the web, and there's a recent
discussion of this topic on this newsgroup as well. I tried to figure
out how to modify it to insert filenames, but I didn't get very far.)

I figured such an algorithm would work something like this:

open dialogue to select files to insert.
iterate over the files to insert {
1. insert filename
2. insert file
}



  #5  
Old March 3rd, 2008, 12:43 PM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default inserting filenames in concatenate-files macro

It will be easier to tell you how to go about this if you post the code that
you already have do the insertion of the files.


Thank you. It's copied below:

Public sBoilerFolder As String

Sub StartBoiler()
' Version 8 - 15 November 2007
' Macro originally created 05/01/97 by Woody Leonhard
' with modifications by Graham Mayor 2006 & 2007
' and by Greg Maxey 2007

Dim fDialog As FileDialog
Dim i As Long
Set fDialog = Application.FileDialog(msoFileDialogFolderPicker)
With fDialog
.Title = "Select Folder containing the documents to be inserted
and click OK"
.AllowMultiSelect = False
If .Show -1 Then
Exit Sub
End If
End With

start:
On Error GoTo error

If Left(sBoilerFolder, 1) = Chr(34) Then
sBoilerFolder = Mid(sBoilerFolder, 2, Len(sBoilerFolder) - 2)
End If
frmBoilerMain.Show
Exit Sub

error:
If Err = 4248 Then
Documents.Add
GoTo start
End If
End Sub
  #6  
Old March 3rd, 2008, 11:45 PM posted to microsoft.public.word.formatting.longdocs
[email protected]
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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 11:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.