Moving Data Between Documents

J

jag

I am working on a project to update between 600-900 old Word job
description/appraisal documents to a newer template format. I have created
my new template file that has the newer format, auto calculations, etc. I now
need to get the data from the older documents into the newer base template.
Most of the data sections in the older documents is static so all of that
data is in my new base template. I'm looking for the best, easy way to get
the data needed moved into the new templates.

Guess I'm looking for a way other than to have to open each of the old
documents, copy/paste the needed data (several sections of data to
copy/paste), then save the new template file for each one.

Any help/ideas would be appreciated..

thanks
 
H

Helmut Weber

Hi,

as far as I understand that, this is the scenario:

You've got documents, based on old templates.
You've created new templates.
Now you want to create new documents, based on the new templates,
and move data from the old documents to the new documents,
as simply applying the new templates to the old docs won't work.

Hardly possible, I'd say, without opening the old documents.

Not a major task, though, if you can define, what data from
which old documents should go to where in which new documents.
It might be possible to transfer data without copying and pasting.

Like this:
RangeInNewDoc.formattedtext = rangeInOldDoc.formattedtext

Given, that the docs are rather simple and short,
whatever that means. ;-)

(Someone in the German groups asked not too long ago,
how to handle documents containing more than 100,000 pages,
which turned out not to be word docs at all, by the way).

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
 
J

jag

Well the old documents are just .doc files, not templates. The old documents
were poorly formated, meaning spacebar used for alignment, no tables, no
sections, etc. There is nothing in the old docs to define the data I need,
however it is in the same location, (same page, headings) in each document,
just worded differently. Could a macro be written that looked for a line of
text, once found, select the text until it found a second line of text, then
that selected text could be copied and pasted to new template file.

Was thinking if I could code a macro to do the following:

open first old doc file
Begin loop
open base template file
copy/paste data from old file to new file
save base template file with newly added data as a new template file
close template file
close old doc file
move to the next old doc file
gotto begin loop

would need some help with the coding of the above...

thanks
 
H

Helmut Weber

Hi,
just in priciple:

Public Sub Test444()
Dim DocOld As Document
Dim DocNew As Document
Dim i As Integer
With Application.FileSearch
.NewSearch
.LookIn = "c:\test\"
.SearchSubFolders = False
.FileName = "*.doc"
.Execute
For i = 1 To .FoundFiles.Count
Set DocOld = Documents.Open(.FoundFiles(i))
Set DocNew = Documents.Add("c:\sample\sample.dot")
' do what you like
DocOld.Close savechanges:=wdDoNotSaveChanges
DocNew.SaveAs "c:\new\" & Format(i, "000") & "new.doc"
DocNew.Close
Next i
End With
End Sub

For a more detailed and elaborate version:

http://www.word.mvps.org/FAQs/MacrosVBA/BatchFR.htm

Note that myFile = Dir$() should not be used,
when adding files to the directory
dir$() looks into. You may end up in an endless loop.

Greetings from Bavaria, Germany
Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word 2002, Windows 2000
 
J

jag

Thanks Helmut, the code works perfect..
Just need help with the following..

I know where the text I need to copy from the old documents is based on text
before and after the text. Example below:

This is the top heading

text I need to copy is here,

This is the bottom heading

How do I go about setting the range start and range end based on my example
above??

Thanks for all the help..
 

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