Reply
 
Thread Tools Display Modes
  #1   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

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   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
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   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

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   Report Post  
Posted to microsoft.public.word.formatting.longdocs
Doug Robbins - Word MVP Doug Robbins - Word MVP is offline
external usenet poster
 
Posts: 8,832
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   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

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   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

Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Concatenate word docs in a folder Eric V Microsoft Word Help 2 March 26th 08 09:08 AM
How do I concatenate string for word wrap (e.g. MK 48)? Darnell_53 Page Layout 2 December 29th 07 11:17 PM
Mail Merge to files with filenames from database [email protected] Mailmerge 2 August 3rd 06 09:37 AM
how to concatenate docs into one word doc Michelle T Microsoft Word Help 3 October 7th 05 05:10 AM
opening word files from windows explorer loses their filenames ecmacd Microsoft Word Help 1 April 27th 05 11:08 PM


All times are GMT +1. The time now is 08:48 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"