View Single Post
  #8   Report Post  
Posted to microsoft.public.word.mailmerge.fields
Peter Jamieson Peter Jamieson is offline
external usenet poster
 
Posts: 4,582
Default Need to nest HYPERLINK within a complex IF (Word 2003/2007)

Is there an order of precedence occuring when you execute the update
(F9 - e.g.
Left-to-Right, inside-out)?


I suspect that that is the normal pattern of execution, but MS could
well have hard-coded some exceptions.

You can verify that some fields are always executed regardless by doing e.g.

{ SEQ X }
{ IF 1 = 1 { SEQ X } { SEQ X } }
{ SEQ X }

Peter Jamieson

http://tips.pjmsn.me.uk

Kent wrote:
Regarding moving the quotes, in our examples the structure looks like:
"{INCLUDETEXT "File_of_Includes" bookmarkforUC_1} "

However, after updating the field (F9) it would sometimes move the
closing quote
following the filename to behind the bookmark, like:
"{INCLUDETEXT "File_of_Includes bookmarkforUC_1"} "

When I started getting the Invalide filename, I noticed that actually
smashed the
bookmark into the end of the filename, so there was no space between
them. I'll try
again this morning.

Is there an order of precedence occuring when you execute the update
(F9 - e.g.
Left-to-Right, inside-out)? I guess I assumed that it wouldn't resolve
and include the
file/bookmark if the condition wasn't met first. But, it's probably
resolving inside-out with
the filename and bookmark first, then determining if it should display
only if the
conditions are true. I'm just speculating based on my earlier life as
a programmer
...a LONG time ago. This is a bit of stretch for me now, but like I
said, I'm trying to keep
it simple for those that I'll be leaving it with.

May be I could pull the filename from a document variable, but it
would
probably have the same problem once it resolved the filename. Worth
checking...

Kent

On Aug 24, 2:56 am, Peter Jamieson
wrote:
I just wish this SOB would react consistently so I could address the
issues appropriately.


IKWYM.

It keeps failing on the
Filename, when
I wasn't changing anything


If you are using exactly the same filename for all the includes, I
suppose this is likely to be something to do with what Word does exactly
when it has loads of INCLUDETEXTs loading stuff from the same file. Does
it open the file once? Open multiple copies? Keep it open? Have a timing
problem? It has never been obvious and nor have I tried to use a monitor
to find out. But Word 2007 is far more likely to have problems in this
area as it seems to do a lot more stuff whenever it opens a file (e.g.
caching it locally etc.).

You may be abe to do something with macropod's discovery that you can
use something like

{IF {INCLUDETEXT {IF TRUE "the pathname"}} {INCLUDETEXT {IF TRUE
"the pathname"}}}

to get Word to resolve the INCLUDETEXT fields completely as it goes along.

it keeps repositioning where the quotes
are being position (behind
the Macro reference"


I lost you on this one, sorry...

Peter Jamieson

http://tips.pjmsn.me.uk



Kent wrote:
Apparently the extra space was dumb luck. I didn't think it would
matter, since it's
part of the True-Text for the IF.
But, now I can't figure out what's going on. It keeps failing on the
Filename, when
I wasn't changing anything, other than the bullet structure. But after
running the CTRL-A, F9
to update all of the fields, it keeps repositioning where the quotes
are being position (behind
the Macro reference". I also wasn't including the '.doc' but now
trying it to fix this latest issue...
I just wish this SOB would react consistently so I could address the
issues appropriately.
Part of it may be self-inflicted, since I'm using 2007, but saving it
as 97-2003 compliant, which
may be injecting other issues... Problem is that most of the readers
most likely still have 2003.
Also, I'm trying to use minimal macros / VBA coding, since the folks
that I'll be leaving this with
are not coders, and I don't want to be married to this long term...
Tomorrow's another day... Hoping I can fix this latest issue on a
fresh pot of coffee in the morning...
Thanks for the advise.
Kent
On Aug 23, 3:26 am, Peter Jamieson
wrote:
that I could put all of the fragments into one separate document, with
bookmarks for
each piece.
I probably should have spelled that out.
I wasn't crazy about having to maintain 2 different
documents
No, it's a pain.
By the way logic works both ways.
Example 1:
{IF {=OR ( { COMPARE { dd_Service } = "'ALL" },{ COMPARE
{ dd_Service } = "UC" }) } = 1
"{INCLUDETEXT "File_of_Includes" bookmarkforUC_1} " ""}
Yes, I didn't get this at first as this was not the result in Word 2007
and I wondered if it only worked in Word 2003, but in fact I'd only
checked an IF with nothing except an INCLUDETEXT in the result, i.e.
{IF {=OR ( { COMPARE { dd_Service } = "'ALL" },{ COMPARE
{ dd_Service } = "UC" }) } = 1
"{INCLUDETEXT "File_of_Includes" bookmarkforUC_1}" ""}
(which does not show the hyperlink behaviour) rather than
{IF {=OR ( { COMPARE { dd_Service } = "'ALL" },{ COMPARE
{ dd_Service } = "UC" }) } = 1
"{INCLUDETEXT "File_of_Includes" bookmarkforUC_1} " ""}
(which does).
Something to bear in mind if you hadn't noticed that you'd left a space
in there!
Another thing worth mentioning at this point is that even with the
original approach, the hyperlink is still "in the document" - you can
check by using VBA to look at Activedocument.Hyperlinks.Count and
.Follow ing the appropriate link. The trouble is that the UI doesn't
provide anything that can follow the link, and even inserting the "Open
Hyperlink" command into the appropriate context menu does not appear to
work. So a macro-based solution may be an option, although I cannot
provide you with a good starting point.
Otherwise, you /may/ be able to improve your current solution by using
using line breaks (shift-enter) rather than paragraph breaks in the
included document.
AFAICR there was quite a lengthy discussion about this type of problem
in this group sometime in 2008, involving macropod and various others. I
haven't been able to find it again and I can't remember whether or not
it was conclusive, but it might be worth having a look on Google groups.
Peter Jamieson
http://tips.pjmsn.me.uk
Kent wrote:
Peter,
Thanks for the idea. I tried to see if I could find any other similar
approaches with
launching the hyperlinks from within Word, maybe an RPC or OLE method
that
may not be widely published, but to no avail.
At first I was concerned that following your approach would result in
hundreds of 1-2
sentence instructional documents, that would then be included
individually, which would
have been a maintenance nightmare. I had to let the idea stew a while
before I realized
that I could put all of the fragments into one separate document, with
bookmarks for
each piece. I wasn't crazy about having to maintain 2 different
documents, but at
least it helps resolve the nested Hyperlink issue, which does work
now. It also helps
resolve some of the sub-bulleting aspects, where my conditional piece
was already on
a bulleted item, and it contained additional sub-bullets. My previous
IF conditions with
Compares, had to be re-included on each additional sub-bullet,
eventhough I already
knew the parent bullet was for that same condition...
By the way logic works both ways.
Example 1:
{IF {=OR ( { COMPARE { dd_Service } = "'ALL" },{ COMPARE
{ dd_Service } = "UC" }) } = 1
"{INCLUDETEXT "File_of_Includes" bookmarkforUC_1} " ""}
Example 2:
{INCLUDETEXT "File_of_Includes" {IF {=OR ( { COMPARE { dd_Service } =
"'ALL" },
{ COMPARE { dd_Service } = "UC" }) } = 1 "bookmarkforUC_1"
"bookmarkforblanktext" }}
If it was just the need for simple logic, it probably wouldn't matter
which format I'd use.
However, almost all of the pieces I need to include when the
conditions are met, are
within a numbered list, or some form of sub-bulleted numbering. For
some reason,
if I use the format on Example 1, Word maintains my numbered formating
for most. I still
have some issues, but it mostly works. I may have a blank area
following the number if the
condition is false, but it is better than what happens with format for
Example 2, where
it uses at least 2 bullet numbers and displays blank lines for both if
the condition is false.
For example if the comparison is on bullet "C" following A, and B,
Example 1 will only use
that position as "C". If I use the format for Example 2, it uses "C"
and "D", and each subsequent
comparison on the next bullets each use up 2 positions, as well.
I have figured out how to keep the bulleted entry from showing by
positioning the IF condition
prior to the bullet number, by forcing a new line anywhere in the
middle of the IF statement.
But the problem is that the line with the logic preceding the bullet
being displayed uses one
of the sequences, similar to Example 2. Controlling the bulleting is
still very "Ify" (no pun intended).
So, I've figured, it's best to just let the single numbered entry, say
"C", exist without content when the
condition is false. I'm currently using a green high-lighting on the
conditional text, so the
readers will see where the document was being filtered, while they get
used to the format (and
blank lines when the conditions are false... lessor of two evils...).
If you have other thoughts along this line I'd be happy to hear them.
But for now, Thanks for the advise!
Regards,
Kent
On 22 Aug, 07:37, Peter Jamieson
wrote:
I don't think it's /just/ the nesting, because if you INCLUDETEXT a
document (or a bookmarked area within a document) that contains a
HYPERLINK field, the link still functions within the document. If you
nest the INCLUDETEXT in the IF, you still have a problem with the
hyperlinks. But if you do e.g.
{ INCLUDETEXT "the path name of a file containing bookmarked areas that
you want to include.doc" { IF { =OR ( { COMPARE { dd_Service } = "ALL"
},{ COMPARE { dd_Service } = "abc" } ) } = 1 "bookmarkname" "nothing" } }
where "bookmarkname" is a bookmark that marks the text etc. that you
need in this case, and "nothing" is the name of a bookmark that does not
mark any text,
then you may get the results you need. But if you include any styled
text (e.g. text with character styles, text that includes paragraph or
section merks etc.) you will probably need to ensure that the styles are
defined the same way in both documents.
Peter Jamieson
http://tips.pjmsn.me.uk
Kent wrote:
I've got a large process document that I'm using a couple of dropdown
fields to filter the selection to help reduce the volume of content.
The reader can either leave it at the defaults for "ALL" regions and
"ALL" services, or they can select an individual region or service
that they want to focus on.
The complex IF works great, except for the Hyperlinks that are within
a majority of the IF statements that direct the reader to external
supporting details, which render my IFs useless, if I can't get to the
details linked to those sections...
Here's a typical example:
{ IF { =OR ( { COMPARE { dd_Service } = "ALL" },{ COMPARE
{ dd_Service } = "abc"

...

read more »- Hide quoted text -

- Show quoted text -