TechWhirl (TECHWR-L) is a resource for technical writing and technical communications professionals of all experience levels and in all industries to share their experiences and acquire information.
For two decades, technical communicators have turned to TechWhirl to ask and answer questions about the always-changing world of technical communications, such as tools, skills, career paths, methodologies, and emerging industries. The TechWhirl Archives and magazine, created for, by and about technical writers, offer a wealth of knowledge to everyone with an interest in any aspect of technical communications.
Subject:Asking for help with Word VB scripting (long) From:Me Too <klhra -at- yahoo -dot- com> To:techwr-l -at- lists -dot- techwr-l -dot- com Date:Thu, 27 Apr 2006 12:46:15 -0700 (PDT)
I have looked in the Microsoft knowledge base and in
the list archives, and found nothing I could use to
solve this problem. So far, all my experiments have
failed.
I have a Word 2003 document, a configuration file,
that contains a lot of IF fields. The document is used
to specify design parameters for the products, things
like # of items included in a certain operation, file
storage locations, names of data fields in batch
files, etc.
It contains IF fields that were intended for
fault-checking. For example, the value that is set in
location X may have to be a specific number in order
to match a value at location Y (the content at both
locations is enclosed in bookmarks). The IF fields
contain code that, during an update, compare the
values and display a message if location X is wrong.
The structure of the fields that concern me is like
this:
As you can see, having an IF field nested like this
creates an IF-THEN-ELSE conditional statement. In this
example, if the content at X is the word "Yes," and
the content at Y is "N/A," nothing appears in the
document. But if location X is the wrong value, the
placeholder string ">>> " appears in the document.
The placeholder string is supposed to indicate places
where there may be problems. After the update, the
user could search the document for that string and
find where values had to be changed. The code works as
intended, but now there's a problem.
The document has grown a LOT and there are now
thousands of these code fields in it. Updates take a
LONG time and the users are complaining. Lots of the
settings, once the first update is done, will not
change again during the life of the project. After the
initial update, the code fields that check for errors
in the stable settings do nothing but add to the time
needed for updates, and the users want a quick and
easy way to remove those fields.
Doing a global search-and-replace for the visible
placeholder strings don't work because they're
generated by the code fields. If they are deleted by a
search-and-replace, they are actually still in the
document and the placeholder strings reappear in the
next update. The only way to permanently remove one of
these strings is to select the actual code field and
delete it. I can make a macro that will find one of
the visible strings, select the code field that
contains it, and then delete that code field, but the
macro does only one at a time. There may be hundreds
of the dern things and removing them individually
takes a long time and wears out the fingers.
I'm trying to make a VB script that will count the
number of visible placeholder strings and then run the
removal macro that number of times. Setting up a Do
loop is the easy part. The problem is, the COUNT
property works on things in the Word domain model, not
on text character strings. I need some way to make
Word consider the ">>> " string an object or field, so
it can be counted. I've tried using the ADD method to
add the string to the FIELDS collection, and it didn't
work; maybe I did it wrong but I don't know enough
about VB to tell.
Any ideas? Thanks for any help I can get.
----------------
Keith Hood
Senior (only) tech writer
ACS, Inc.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
WebWorks ePublisher Pro for Word features support for every major Help
format plus PDF, HTML and more. Flexible, precise, and efficient content
delivery. Try it today!. http://www.webworks.com/techwr-l