Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Mailmerge and Fax / May 2005

Tip: Looking for answers? Try searching our database.

Mass Merging

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dagger Depot - 28 May 2005 16:13 GMT
Is it possible to merge a header into thousands of word documents using
some kind of merging program?  

My company had me working on creating thousands of documents over the
last couple of weeks, and now decided they want a company header put
into the documents.  These have to be done this weekend; no "if's,
and's or but's about it".  

Any help will be extremely appreciated.

Signature

Dagger Depot

Doug Robbins - 29 May 2005 08:19 GMT
If the letters were originally created using mailmerge, the simplest thing
would be to modify the mailmerge data main document by placing the necessary
information in the header and then re-execute the merge.

Otherwise, I would create a template with the necessary header information
in it and then use a modification of the code in the article the article
"Find & ReplaceAll on a batch of documents in the same folder" at:
http://word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

to set a Range to the text in each letter, create a new document from the
template and then insert the Range into that document.

Post back if you need help with the VBA code.

Signature

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

>
> Is it possible to merge a header into thousands of word documents using
[quoted text clipped - 6 lines]
>
> Any help will be extremely appreciated.
Doug Robbins - 29 May 2005 09:22 GMT
Here is the code that you will need.  BEFORE RUNNING THE CODE, I would
suggest that you make a copy of all of the documents in another folder just
in case something goes wrong.

Dim myFile As String, PathToUse As String, SourceName As String
Dim Source As Document, Target As Document
'Modify the path in the following statement so that it points
'to the folder where the documents are located.
PathToUse = "C:\Test\"
'Close all open documents before beginning
Documents.Close SaveChanges:=wdPromptToSaveChanges
myFile = Dir$(PathToUse & "*.doc")
While myFile <> ""
   'Create a new document containing the header information.
   Set Target = Documents.Add("template with the header in it.dot")
   'Open document containing the text
   Set Source = Documents.Open(PathToUse & myFile)
   'Get the name of the document
   SourceName = Source.FullName
   'Set the text in the new document equal to the text in the source
document
   Target.Range.FormattedText = Source.Range.FormattedText
   'Close the source document
   Source.Close wdDoNotSaveChanges
   'Save the new document with the name of the source document
   Target.SaveAs SourceName
   'Next file in folder
   myFile = Dir$()
Wend

Signature

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

>
> Is it possible to merge a header into thousands of word documents using
[quoted text clipped - 6 lines]
>
> Any help will be extremely appreciated.
Graham Mayor - 29 May 2005 09:38 GMT
You could do this with a batch processing macro, provided all the documents
are in the same folder.

The following macro http://www.gmayor.com/installing_macro.htm  will replace
the existing header with whatever header you first save as an autotext entry
called 'logo'.

If you wish to *add* the company header to an existing header, the code will
require modification - and if some of the documents have multiple sections
you will have to add code to process those sections, but the basic code will
work for simple documents. Try it on a few copies in a folder created for
the purpose.

If you want more help with this I will not be around again this weekend. Ask
your further questions in the VBA newsgroup.

Sub AddAHeader()
Dim myFile As String
Dim PathToUse As String
Dim myDoc As Document

' Get the folder containing the files
' Save the header to insert as an autotext entry
' called 'logo'
With Dialogs(wdDialogCopyFile)
   If .Display <> 0 Then
       PathToUse = .Directory
   Else
       MsgBox "Cancelled by User"
       Exit Sub
   End If
End With

'Close any documents that may be open
If Documents.Count > 0 Then
   Documents.Close Savechanges:=wdPromptToSaveChanges
End If

If Left(PathToUse, 1) = Chr(34) Then
   PathToUse = Mid(PathToUse, 2, Len(PathToUse) - 2)
End If

myFile = Dir$(PathToUse & "*.doc")

While myFile <> ""

   'Open each file and make the replacement
   Set myDoc = Documents.Open(PathToUse & myFile)
   ActiveWindow.ActivePane.View.SeekView = wdSeekCurrentPageHeader
       Selection.WholeStory
   Selection.Delete Unit:=wdCharacter, Count:=1
   Selection.Style = ActiveDocument.Styles("Normal")
   NormalTemplate.AutoTextEntries("Logo").Insert Where:=Selection.Range, _
       RichText:=True
   ActiveWindow.ActivePane.View.SeekView = wdSeekMainDocument
   myDoc.Close Savechanges:=wdSaveChanges
   myFile = Dir$()
Wend

End Sub

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Is it possible to merge a header into thousands of word documents
> using some kind of merging program?
[quoted text clipped - 5 lines]
>
> Any help will be extremely appreciated.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.