Syntax / logic help

T

Top Spin

I would appreciate some ideas or suggestions on the overall logic or
structure of a little VBA application I would like to have written.

In my business, I have various services I offer to clients. Let's call
them service A, B, C, etc.

These services also have a few general attributes such as
"confidential"/"non-confidential" or "court-ordered"/"not
court-ordered".

Right now, I have about 10 different contract templates (Word) for
various clients, such as "Service A, confidential", or "Service C,
court-ordered, not confidential", etc.

Most of the clauses in these contracts are the same or very similar. I
would like to consolidate all of the templates into one master
template containing all of the clauses that might be needed by any
type of service and then write a macro to delete the clauses that are
not needed for the type of service at hand.

My first idea was to put some type of delimiter into the template just
before each clause to indicate which types of services it applies to
so the macro would know which clauses to delete and which to keep.

So I need some syntax for the delimiters that would be unique and
simple to use. My first thought was something like:

/a/c/f

which would mean: include the text that follows in contracts for
services A, C, or F. The template might look something like this:

/a/b
Text of clause to be used for type A and B services.
/c
Text of clause to be used only for type C services.
/all
Text of clause to be used for all services.

The macro would scan for delimiter lines, then include or exclude all
of the text up to the next delimiter line depending on whether the
service type being processed matched the delimiter or not.

When I started putting the delimiters into the template, I quickly
realized that there a quite a few clauses that apply to all services,
but they are slightly different for one or two types. What I want for
them is a way to say: use this clause for Service A, this for service
B, and this for all the others. For example:

/a
Text of clause to be used for type A services.
/b
Text of same clause to be used for type B services.
/"all the others (not a and not b)"
Text of same clause to be used for all services other than A or B.

It's that "all the others" that my simple syntax doesn't accomodate.

I know I could implement a complete boolean syntax like

/(^a)&(^b)
Text of same clause to be used for all services other than A or B.

But I would prefer not to write a general-purpose parser. I would also
like to avoid repeating the "a" and "b", in case I add a special
version for type C so I won't have to remember to change "/(^a)&(^b)"
to "/(^a)&(^b)&(^c)".

I thought about introducing "groups" of clauses and have the macro
keep track of which types have been used so I could have an "all the
rest" clause at the end. Something like this:

//group
/a
Text of clause to be used for type A services.
/b
Text of same clause to be used for type B services.
/e
Text of same clause to be used for type E services.
/
Text of same clause to be used for all services other than A, B, or E.
//end

The //group would start a group. The macro would remember that it had
seem clauses for A, then B, then E, so when it encountered the null
"/", it would include that text for all tyoes that it had not seen.
The "//end" would close that group.

It there something simpler and more elegant?

Thanks
 
P

Peter Hewett

Hi Top Spin

Investigate the use of Bookmarks and AutoText entries. Bookmarks define a
location in your document marking preexisting text and/or a location for new
text. AutoText entries are formatted blocks of text/graphic that are stored in
a template. They can include almost any element text, tables, formatting,
bookmarks, graphics etc, etc. Each AutoText entry is assigned a name when it's
created so retrieving an AutoText entry is simple.

You will probably need a UserForm to provide a user interface that allows you to
select various options that in turn result in different AutoText entries being
inserted into your document.

Set up correctly this type of solution is flexible and elegant. If you design
it carefully you'll find you change the AutoText much more frequently that you
do the code, which is exactly what you want.

To start identify the various chunks of text you want to assemble. Whether you
use lots of little block or less larger blocks is up to you.

You need a user form to allow the user to select which document type you want
built. Code the form so that for each type document produced a different
subroutine/procedure is run. This keeps things nice and modular and you can
then change the way you create one document without screwing up the others!!

As a starting point check out this link:

Userforms FAQ - How to create a Userform:
http://word.mvps.org/FAQs/index.htm

This is where the majority of your code will reside. The code to take an
AutoText entry and update a bookmark is trivial and we can post that later.

Focus on the form and the autotext entries you'll need to get this off the
ground.

HTH + Cheers - Peter
 
T

Top Spin

Hi Top Spin

Investigate the use of Bookmarks and AutoText entries. Bookmarks define a
location in your document marking preexisting text and/or a location for new
text. AutoText entries are formatted blocks of text/graphic that are stored in
a template. They can include almost any element text, tables, formatting,
bookmarks, graphics etc, etc. Each AutoText entry is assigned a name when it's
created so retrieving an AutoText entry is simple.

I've played around with both bookmarks and autotext in the past and
found them problematic.

The problem I had with bookmarks is that they did not stay put. This
template will get a lot of editing and my experience was that it was
way too easy to mess up the bookmarks when text was moved, copied, or
inserted.

With autotext, I found it very difficult to manage. A lot of stuff
happened "under the covers" unexpectedly. I spent a lot of time
debugging it and never really ever got it working properly.

This was a couple of releases back. Have things improved?

I am intrigued by this proposal. If it can be made to work, I have
another application that might be an even better use of it. It's just
that I had a very bad experience with it.
You will probably need a UserForm to provide a user interface that allows you to
select various options that in turn result in different AutoText entries being
inserted into your document.

I haven't used userforms, so I'll have to check that out.
Set up correctly this type of solution is flexible and elegant.

Yes, that would be great.
If you design
it carefully you'll find you change the AutoText much more frequently that you
do the code, which is exactly what you want.

To start identify the various chunks of text you want to assemble. Whether you
use lots of little block or less larger blocks is up to you.

You need a user form to allow the user to select which document type you want
built. Code the form so that for each type document produced a different
subroutine/procedure is run. This keeps things nice and modular and you can
then change the way you create one document without screwing up the others!!

As a starting point check out this link:

Userforms FAQ - How to create a Userform:
http://word.mvps.org/FAQs/index.htm

OK, will do. Thanks.
 
P

Peter Hewett

Hi Top Spin

I've implemented solutions using this approach for a number of my clients, and
it's worked well for them in practice. Although bookmarks can be deleted, if
you turn on View Bookmarks it becomes less of a problem. You can also add code
that checks that critical bookmarks exist before you save your template. If you
believe the template will be very dynamic you may have problems in developing
and keeping a user interface in sync with your changes.

You could insert fields (maybe a Quote field) in the template and use the
contents of the field as it's name and then replace the field with text. But
you can delete fields pretty easily as well.

I've used AutoText extensively and found it reliable and robust. I've provided
code to my clients that perform all sorts or tricks with AutoText. I had one
that wanted to reorder 30 - 120 paragraphs using a ListBox to move the
paragraphs up and down. And of course AutoText to the rescue with heaps of
entries being added and deleted dynamically.

Good luck + Cheers - Peter


I've played around with both bookmarks and autotext in the past and
found them problematic.

The problem I had with bookmarks is that they did not stay put. This
template will get a lot of editing and my experience was that it was
way too easy to mess up the bookmarks when text was moved, copied, or
inserted.

With autotext, I found it very difficult to manage. A lot of stuff
happened "under the covers" unexpectedly. I spent a lot of time
debugging it and never really ever got it working properly.

This was a couple of releases back. Have things improved?

I am intrigued by this proposal. If it can be made to work, I have
another application that might be an even better use of it. It's just
that I had a very bad experience with it.


I haven't used userforms, so I'll have to check that out.


Yes, that would be great.


OK, will do. Thanks.

HTH + Cheers - Peter
 
T

Top Spin

Hi Top Spin

I've implemented solutions using this approach for a number of my clients, and
it's worked well for them in practice.

Do you take contract work? I tried to send you an email to the address
shown here, but it bounced back. Do you have another email address?

You can email me at the address shown below:
 

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