• AutoHyphenation = False not working (2003)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » AutoHyphenation = False not working (2003)

    Author
    Topic
    #448358

    (Edited by jscher2000 on 05-Feb-08 14:02. Moved to a new thread and retitled.)

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1096292

      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.

      • #1096294

        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.

        • #1096296

          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)

          • #1096297

            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.

            • #1096298

              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.

            • #1096307

              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!

              Thx.

            • #1096314

              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

            • #1096335

              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!

            • #1096352

              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:

              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

              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.

            • #1096371

              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. blackteeth

            • #1096374

              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.

            • #1096379

              Repaint belongs to userforms, not to Word.

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

            • #1096397

              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!

            • #1096399

              I’m afraid I’m out of ideas too (except turning off hyphenation altogether grin)

            • #1096410

              The following works for me using Word 2002 and some text with fairly basic formatting:

              ActiveDocument.AutoHyphenation = False
              Selection.Cut
              Selection.Paste
              ActiveDocument.AutoHyphenation = True

            • #1096411

              Thanks, let’s hope that it works for Richard in Word 2003.

            • #1096436

              It’s moot now, but I did most of the testing on a PC with Word 2002 SP3. I’m now on a PC with Word 2003 SP3, and it behaves exactly the same as Word 2002 for me: the problem doesn’t occur at all. Automatic hyphens aren’t copied when I copy/paste to another application.
              You might want to try Phil Rabichow’s Systematic Approach to Behavioral Problems in Word.

              Notes:
              – Soft hyphens are copied to other applications, but none of the macros discussed in this thread help with that – they become part of the text.
              – Turning autohyphenation off and on in a large document is irritatingly slow even on a very fast PC.

            • #1096556

              Being a slow day here, I’ve been doing some testing and found that automatic hyphens are carried over to the following applications:

              Notepad (Windows 2000, SP4)
              TextPad (4.7.3)
              A form in the Mozilla browser (1.7.3)
              Netscape Composer (4.79)

              They’re not, however, carried over to the following applications:

              Word, Excel, PowerPoint or FrontPage (2002, SP3)
              Visio Standard (2002)
              A form in Internet Explorer (6)
              Mozilla Composer or Mail (1.7.3)
              WordPad (Windows 2000, SP4)

              I’m not really sure what this means. Perhaps that – almost all of – the Microsoft products are compatible?

            • #1096557

              Interesting – thanks. It looks like most Microsoft applications (except the rather primitive Notepad) indeed don’t transfer the soft hyphens. BTW, soft hyphens don’t carry over from my Word 2002 to Notepad. Go figure…

    Viewing 0 reply threads
    Reply To: AutoHyphenation = False not working (2003)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: