SERIOUS Automation...your advice, please

A

Angyl

In the process of my job I often find myself duplicating information. I have
learned enough from these boards in the last month to know that it is
probably possible to save myself the trouble of a few steps.

What I have before me is a form with a LOT of fields in it that are
bookmarked.

I also have saved on my system a form with a LOT of fields in it that share
many of the same bookmark names.

I want to make one of these forms, automatically creaate a NEW document
based on a template of the OTHER document and then populate the boomarked
fields in that new document with its existing data.

Make sense?

I've already managed to (learned how) to make two documents "talk" to each
other, so I suppose all I'm looking for is the code to tie this all together
at once, perhaps putting a macro in the last field of the document that will
run on exit

This will open the document from a template:

Sub OpenPayrollReport()
'
' Macro2 Macro
' Macro recorded 5/5/2006 by Timothy Allen
'
Documents.Add Template:= _
"C:\Documents and Settings\tallen\Application
Data\Microsoft\Templates\Policy Payroll Report.dot" _
, NewTemplate:=False, DocumentType:=0
End Sub

I need to expand that macro to tell the new document to point all of its
bookmarked fields to the current document I have open, and (optionally) go
one step further and SAVE that new document based on the text entered in one
of the fields!!

WEEEEE Give me lots more time in my life to be further exploited by my boss!!
 
G

Greg Maxey

Hmm...your only question was, "Make sense?"

Answer: No.

Have you considered using IncludeText fields. If you have a document
filed away with information bookmarked, you can use that information in
an existing document by extracting the information from the other file
using an IncludeText field.

Lets say I have a document. C:\Answers to smart alec questions.doc

In it I have some text bookmarked bkNotForTenderEars

In a new document I type an example smart alec question:

Do you two want to be left alone? { IncludeText "c:\\Answers to smart
alec questions.doc" "bkNotForTenderEars" }

Would this work ;-)
 
D

Doug Robbins - Word MVP

What I would do is combine both documents into separate sections in the
template, using cross reference fields in the document in the second section
to the bookmarks assigned to the formfields in the first section with the
"Calculate on exit" box checked for each formfield so that the cross
references are updated, then you could use a modification of the following
macro to split the document into two, one section to each, saving them with
names that you can get from the .Result property of the formfields.

Sub splitter()
' splitter Macro
' Macro created by Doug Robbins to save each letter created by a mailmerge
' as a separate file, retaining the header and footer information.
Dim i As Long, Source As Document, Target As Document, Letter As Range
Set Source = ActiveDocument
For i = 1 To Source.Sections.Count
Set Letter = Source.Sections(i).Range
Set Target = Documents.Add
Target.Range = Letter
Target.Sections(2).PageSetup.SectionStart = wdSectionContinuous
Target.SaveAs FileName:="Letter" & i
Target.Close
Next i
End Sub



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

Angyl

Greg, yes that would work...

technically...

but the problem is that the original document contains AT LEAST two-hundred
form fields.

(don't look at me, I didn't make it)

Most are not used, some are...it varies.

Could you imagine trying to update the file location for all of 'em, every
time you were filling out a different client?

That's why I was lookin to "automate" the process.
 
A

Angyl

Having a little trouble with the code, Doug. I've tried using section page
breaks and section continuous breaks (a the code states) but the macro always
returns an error that the requested collection member doesn't exist on this
line:

Target.Sections(2).PageSetup.SectionStart = wdSectionContinuous
 
H

Helmut Weber

Hi Angyl,

can't test it, because of lack of testing material,

but try:
(To be viewed best with Courier New or another non proportional font)

Target.Sections(1).PageSetup.SectionStart = wdSectionContinuous
^
Or try commenting out that line altogether.

IMHO, if a doc contains only one section,
then it does't matter, what kind of
PageSetup.SectionStart there is.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
D

Doug Robbins - Word MVP

You did use Insert>Break to create the second Section of the form document
did you?

In your case, in your form document, I would use a Continuous Section Break
rather than a Next Page Section Break and then you will not need that line
of code.

The code was written for splitting a document created by executing a
formletter type mailmerge to a new document in which case the execution of
the mailmerge inserts Next Page Section Breaks and when you then split the
letter into individual sections, at the end of the letter, you have a Next
Page Section Break which causes there to be a blank page at the end of every
letter.

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

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