Page 1 of 3 123 LastLast
Results 1 to 15 of 31
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    'Keep together', different version (WinNT/Word97)

    Hi folks - I'm still having fun with this <img src=/w3timages/censored.gif alt=censored border=0> template full of docvariables!

    Background:
    <UL><LI>I have a set of 20 variables, in pairs, each pair consisting of one for a heading and one for the content (this is because i haven't discovered a way to format part of the content of a docvariable differently to the rest - is there a way, does anyone know?! Not that it would help, I don't think ...).
    <LI>None of the variables are guaranteed to be used on any particular occasion, but if left empty the VBA says they've been deleted, so they've all been filled with a space each so they don't take any vertical room when not in use (again, if anyone knows a better way to hold them, I'm open to suggestions!).
    <LI>When they are in use, each will consist of two carriage returns and the appropriate text.
    <LI>I have no control over where on a page they will appear as there are several points where the content can vary considerably in size in the foregoing parts of the template.
    <LI>The user cannot touch the text; they supply all their input via userforms, the document itself is protected and the code removes extraneous carriage returns before entering the text.[/list]Now the problem - how do I stop the heading part of a pair of variables being left at the bottom of one page when the content is on the next page?!

    I can't use keep with next or keep together because (1) if I apply it to the document, when unused all 20 variables are in one paragraph so the entire section would 'keep together' when used - covering up to a couple of pages! - and (2) I haven't managed to find a way to apply either of them programmatically in a way that would stick when they're used and not cause problems when they're not!
    Can anyone help me, please? <img src=/S/grovel.gif border=0 alt=grovel width=31 height=23> I'm happy to be pointed in an entirely different direction if I'm on the wrong track!

    Many thanks
    Beryl M


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Can't you apply the "Keep with next" to each non-blank-or-space heading text immediately after it has been inserted?

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Well, you would have thought so, wouldn't you?! I've tried - but that's what I meant when I said I haven't found a way to do it programmatically. So far the code for each pair looks like this:
    <pre> If frmM2.chkBorBack = True Then
    adVar("addfBorBackt") = Chr(13) + Chr(13) + "Borrow Back"
    adVar("addfBorBack") = Chr(13) + Chr(13) + txtBorBack
    aD.Content.Find.Execute findText:="Borrow Back", Forward:=True
    Selection.ParagraphFormat.KeepWithNext = True
    Else
    adVar("addfBorBackt") = " "
    adVar("addfBorBack") = " "
    End If</pre>

    (adVar = activedocument.variables, ad = activedocument; I got fed up with the length of the code lines I was dealing with and assigned them to variables to shorten them!).

    The third and fourth lines of the first half are my efforts so far. The find line works fine but although the format line doesn't complain, it doesn't work either.

    <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>

    PS This template currently contains four, almost full screen size at 800x600, forms (and one little one) and 25 printout pages of code, and you wouldn't believe how tempted I've been to just ask you to look at it and condense it to 3 or 4 pages, as you did to one of my templates before (well, ~3 pages down to about 20 lines, I think it was) but don't worry, I'm not going to! Much as I'd love to have the code beautifully streamlined, I think you've got enough on your plate! <img src=/S/wink.gif border=0 alt=wink width=15 height=15>
    Beryl M


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    I think the problem is caused by the paragraph marks Chr(13). The "heading" paragraph is kept together with the next one, but that is an empty paragraph. See if it works better if you replace the second Chr(13) by Chr(11) i.e. a manual line end. Alternatively, you could do away with the second Chr(13), and format the paragraph to use space before, through the style definition, or in code using Selection.ParagraphFormat.SpaceBefore.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Unfortunately, no, it's not that - the keep together just doesn't stick at all! ie, none of the paragraphs in the variables have any keep togethers on them! At least, they don't on mine ... It's as if it doesn't see the chr13s as chr13s since they're inside docvariables.

    double <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15>
    Beryl M


  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    I'm afraid Word's behavior is buggy here. I've been experimenting, and my impression is that Word largely ignores paragraph settings such as Space Before and Space After and Keep with Next in (DocVariable) fields. Nothing I have tried accomplished what you want. Sorry.

  7. #7
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Oh, well - thanks for trying, Hans! <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    It's a pity that trick with the { eq } fields I tripped over for Chris wouldn't work here <img src=/S/sigh.gif border=0 alt=sigh width=15 height=15> - and if you're wondering, that's because it comes up with an error if you put any character in it that makes a new line! Actually, your space before and after idea would probably work then; but one of the last things the template does is disconnect all the fields and make them ordinary text, so it would fall apart then ...

    <img src=/S/lightbulb.gif border=0 alt=lightbulb width=15 height=15> Hang on - I just thought of something ... If I had it fill in the heading docvariable with just part of the heading, then take the cursor to that variable and put the rest of the heading *outside* the variable, as ordinary text - or maybe just the returns, before and after - would it then let me put a keep together on them, do you think?

    Hmmm <img src=/S/hmmn.gif border=0 alt=hmmn width=15 height=15> ... I'm going to have to go and think about that ...
    Beryl M


  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    If you're going to disconnect the fields anyway, why not unlink them and then apply the paragraph formatting, or even insert everything as text instead of fields? You could have predefined bookmarks to mark the locations for insertion.

  9. #9
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Because when they want to edit the letter, since they can't touch the text, I have to be able to pick it all back up again and re-populate the forms with the info. And a lot of this info is freeform text so there would be no way (at least that I know of!) to be sure that I *have* picked up all the content, *without* touching the bookmarks - and allowing for the occasions when none of these fields are required at all!

    I can play with the chr13s before and after, or even a bit with the headings text since that is standard, but not with the content of each one, and I need to keep the docvariable as a 'landmark', as it were.

    That's given me an idea, though - it's always irritating me that you can't actually say "go to the docvariable called "addfborback", you can only specify the type of variable and which number of the collection it is ... unless you know different? [hopefully]. I could add bookmarks to give the "goto" somewhere exact to go to ...

    Don't worry, Hans, even if you haven't known the answer off pat this time (most unusual! <img src=/S/grin.gif border=0 alt=grin width=15 height=15>), you're definitely being a great help! It's a times like these that I wish I wasn't the only person with any real knowledge of VBA in my company - having someone to bounce ideas off of makes a big difference!

    Many thanks! <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>
    Beryl M


  10. #10
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    <hr> It's a times like these that I wish I wasn't the only person with any real knowledge of VBA in my company - having someone to bounce ideas off of makes a big difference! <hr>
    I'm in the same position here in the office and I feel exacly the same!

  11. #11
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    <img src=/S/yep.gif border=0 alt=yep width=15 height=15>
    Beryl M


  12. #12
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Just to let you know, after a bit - well, a lot - of fiddling, I found that a combination of the two <img src=/S/lightbulb.gif border=0 alt=lightbulb width=15 height=15> moments did the trick; I put a suitably named bookmark in front of each docvariable, then goto'd to it and added two returns when wanted; then goto'd to them again and used 'Del' to remove them when no longer wanted.

    With suitable failsafes (to ensure the returns aren't added when already there, or removed when not) and written up as a couple of functions including the keepwithnexts, it was <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22> !!

    Thanks again for your help!
    Beryl M


  13. #13
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Glad you were able to solve it (without my help)!

  14. #14
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Morden, Surrey, United Kingdom
    Posts
    1,838
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Re: 'Keep together', different version (WinNT/Word97)

    Oh, I wouldn't say it was *without* your help - as I said, both the <img src=/S/lightbulb.gif border=0 alt=lightbulb width=15 height=15> moments were prompted by comments you made!

    Actually, it's rather nice to have worked out an answer for myself occasionally, rather than just have it given to me - but usually the best answer is something I would never have thought of for myself, because it'll use something I've never heard of, or just haven't quite got to grips with!

    BTW, I've cut that 25 pages of code down by about 3 so far, by spotting places where I can apply methods you showed me that time, eg using custom functions so you don't have to repeat the same or very similar code over and over again.

    I'm learning ... slowly ... !

    <img src=/S/thankyou.gif border=0 alt=thankyou width=40 height=15>
    Beryl M


  15. #15
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: 'Keep together', different version (WinNT/Word97)

    Hi Beryl
    If I' ve misunderstood your comment; apologies. In response to
    <hr>it's always irritating me that you can't actually say "go to the docvariable called "addfborback", you can only specify the type of variable and which number of the collection it is ... unless you know different? <hr>
    I often use code similar to the following:

    <pre> With ActiveDocument
    For i = 1 To .Shapes.Count
    If .Shapes(i).Name = "addfborback" Then
    .Shapes(i).Select
    Exit For
    End If
    Next i
    End With
    </pre>



    I have never used docvariables, so this may be off track, but I hope it helps.
    Regards
    Don

Page 1 of 3 123 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •