Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    AutoHyphenation = False not working (2003)

    <P ID="edit" class=small>(Edited by jscher2000 on 05-Feb-08 14:02. Moved to a new thread and retitled.)</P>At the office, I can't create a new post, so I'm replying to one of my older posts. I'm now using Word 2003. I keep hyphenation on by default. I have a macro that supposedly turns off hyphenation, then copies the selection, and then turns hyphenation back on (code is below). I want to do this because sometimes I past selections from Word into other applications (e.g., something running in Internet Explorer) and don't want the hyphens to appear in the pasted text. I thought my code below worked in versions prior to Word 2003, but it doesn't seem to be working now. Whenever I paste the selection, there is a hyphen in the middle of some words.

    ActiveDocument.AutoHyphenation = False 'Turns off hyphenation before copy
    Selection.Copy
    ActiveDocument.AutoHyphenation = True

    I thought maybe the problem was that the macro was moving too fast and grabbing the selection before hyphenation could be turned off in the selection. If I step thru the macro using F8 in the VB Editor, it works fine!! However, when it runs at regular speed, it doesn't!!

    I tried adding ScreenUpdate = Refresh (or something like that) after turning hyphenation off. That didn't work. I tried adding a for loop to try to pause the macro a bit, but that didn't work either (I might not have created a long enough loop, but who knows -- I only use x = 1 to 25).

    The following works, but doesn't always give me the results I want when I paste, so I'd like to get the hyphenation on/off method to work.

    Selection.NoProofing = True 'Hyphenation not working, but NoProofing works
    Selection.Copy
    Selection.NoProofing = False

    I thought of the above after searching for hyphenation macros here and running across my original post about the single word no hyphenation macro.

    Anyway, the problem with the noproofing method is that I'm copying bulleted lists from a table cell, and the last item does not have a hard return/paragraph marker (just the end of cell/row marker). If I use my hyphenation code, and select the period before the end of the bullet, and paste into my other application, the bullets appear as little dots. However, if I use the noproofing method, the last bullet does not appear (because I'm not able to select a final hard return/paragraph mark at the end).

    Any suggestions on getting the hyphenation method to work? Is there some way to force a redraw of the screen that might do what I want? I thought maybe there was a way to turn off the selection, turn off hyphenation, then turn the same selection back on, but I couldn't quite figure that out either. I can't seem to find something to re-select. I suspect it exists; I just can't find it.

    Thanks for the help.

    -Rich

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

    Re: AutoHyphenation = False not working (2003)

    Are you talking about the hyphens that Word inserts when automatic hyphenation is on, or about soft hyphens (Ctrl+hyphen) inserted manually? Only the latter are included when I copy and paste from Word into another application.

  3. #3
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    I'm talking about the hyphens Word inserts when automatic hyphenation is on. Your system may be different from mine, but if I copy a selection of text that has a hyphen in it because of auto hyphenation, the hyphen appears in my pasted text, like so (see the one in "outside") (which I just pasted after copying it in Word with auto-hyphenation on):

    Work on reviewing revised lease from LL, but then engaged out-side counsel to complete negotiations.

    If I turn auto-hyphenation off before copying the text, it pastes like this (which is what I want):

    Work on reviewing revised lease from LL, but then engaged outside counsel to complete negotiations.

    My macro used to work, at least most of the time. After I selected the text, I ran the macro and it turned off auto-hyphens before the text was copied, so the hyphens weren't copied, but that doesn't seem to be working in Word 2003.

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

    Re: AutoHyphenation = False not working (2003)

    Yes, apparently it works differently for you and me. I haven't been able to find anything relevant about your problem, but if I do, I'll post it here.

    (I turned off automatic hyphenation off years ago and never missed it; I just turned it on temporarily to test for this thread)

  5. #5
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    Is there some way to "pause" a macro for a specific length of time? When my macro runs, the screen redraws when it gets to the hyphenation off command, but somehow the selection.copy is occuring before that. If I could pause the macro for a bit, that might help. Thx.

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

    Re: AutoHyphenation = False not working (2003)

    Does it help if you insert a line

    DoEvents

    above the line with Selection.Copy? If not, you could try this:

    Sub CopyNoHyphens()
    ActiveDocument.AutoHyphenation = False
    Application.OnTime Now + TimeValue("0:00:01"), "CopyNoHyphens2"
    End Sub

    Sub CopyNoHyphens2()
    Selection.Copy
    ActiveDocument.AutoHyphenation = True
    End Sub

    The macro to execute is CopyNoHyphens. It turns off auto-hyphenation, then calls CopyNoHyphens2 with a delay of 1 second (you can change that if you like). CopyNoHyphens2 copies the selection, then turns auto-hyphenation on again.

  7. #7
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    Thanks for the suggestions, but while your code is fine, it doesn't help the problem (i.e., Word still copies the hyphenation selection rather than the un-hyphenated selection). I hate to keep bugging you, but you probably have this code save some way, but is there a way to turn the selection off and then re-select what was selected? I thought I've seen code like this before, and may have even used it, but can't recall it or find it now. My thought is that I run the macro with the selection on. I turn the selection off. Turn hyphenation off. Then re-select the original selection (I don't know, maybe the code puts a bookmark at the end, and then the bookmarked text is select, or something like that). At this point, hyphenation should be off when selection.copy is executed. I could then delete the bookmark. Hmm, this gives me thoughts, but before I try something from scratch, I suspect you have something ready-made that would likely work better anyway! <grin>

    Thx.

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

    Re: AutoHyphenation = False not working (2003)

    I don't understand what "turning off the selection" has to do with your problem. However, you could try this:

    Sub CopyNoHyphens()
    Dim rng As Range
    Set rng = Selection.Range
    Selection.Collapse wdCollapseEnd
    ActiveDocument.AutoHyphenation = False
    rng.Select
    Application.OnTime Now + TimeValue("0:00:01"), "CopyNoHyphens2"
    End Sub

  9. #9
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    I was just trying to select the selection when I knew for sure the hyphenation was off. However, it doesn't work. It's funny. If I step thru the macro with F8, using your range code, or just using my simple hyphenation off code, it works the way I want it to (i.e., the hyphens are not picked up in the copied selection). However, as soon as I run it at regular speed, it doesn't work and the "copy" includes the hyphens. I don't know what to do at this point. If someone else ever chimes in with an idea, that'll be great. Thanks for all your help so far!

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

    Re: AutoHyphenation = False not working (2003)

    How about this variant? Put the following declaration near the top of the code module, above the Subs:

    Private rng As Range

    Change the two macros as follows:
    <code>
    Sub CopyNoHyphens()
    Set rng = Selection.Range
    Selection.Collapse wdCollapseEnd
    ActiveDocument.AutoHyphenation = False
    Application.OnTime Now + TimeValue("0:00:01"), "CopyNoHyphens2"
    End Sub

    Sub CopyNoHyphens2()
    rng.Copy
    ActiveDocument.AutoHyphenation = True
    End Sub
    </code>
    The range is copied in the second macro - the one being executed after a delay of 1 second - instead of immediately after turning off hyphenation in the first macro.

  11. #11
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: AutoHyphenation = False not working (2003)

    Maybe if you issue a "repaginate now" command the auto-inserted hyphens will get removed by Word, and then you can copy that passage without them. I'm not sure there actually is such a command, however. <img src=/S/blackteeth.gif border=0 alt=blackteeth width=20 height=20>

  12. #12
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    Hans, again your code is OK, but the hyphens are still there. I even recorded some code to try it with bookmarks. No matter what I do, the hyphens appear in the pasted text. It's like Word remembers what was selected originally and copies that rather than the selected text that doesn't have a hyphen. I'm wondering if maybe there's still some hidden hyphen code there when it re-selects the text. Who knows...

    I looked around for some page redraw command per jscher's suggestion. I found the .repaint method, but I can't seem to structure the code correctly. I keep existing my macro with an error. It's supposed to look like this: Boolean = object.Repaint. I figure "=Page.Repaint" a command, but I'm lost on structuring the boolean (although I know it's just true/false). Any idea on if this might work if I knew how to structure the code properly?

    Thx.

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

    Re: AutoHyphenation = False not working (2003)

    Repaint belongs to userforms, not to Word.

    ActiveDocument.Repaginate forces Word to recalculate the pagination of the document.

  14. #14
    3 Star Lounger rcbjr2's Avatar
    Join Date
    Jan 2001
    Location
    Matthews, NC
    Posts
    279
    Thanks
    6
    Thanked 1 Time in 1 Post

    Re: AutoHyphenation = False not working (2003)

    Thanks, but that doesn't work either. I give up. The only thing that works is NoProofing, although that doesn't work when copying text in a table that has a bullet assigned unless there is an ending mark instead of the cell/row ending code. I just don't understand why it works just fine if you F8 thru the macro code, but doesn't if you just run the macro. That is just too strange. Oh well. Thanks for your great help!

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

    Re: AutoHyphenation = False not working (2003)

    I'm afraid I'm out of ideas too (except turning off hyphenation altogether <img src=/S/grin.gif border=0 alt=grin width=15 height=15>)

Page 1 of 2 12 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
  •