Jeff_VB
10-28-2023, 06:54 AM
I'm posting this workaround for others as it's been incredibly annoying to copy a list line and have it also copy the line number that I did not select for copy. Actually, I'm surprised that Microsoft has not provided a fix for this problem; even for Microsoft this is a bad problem to leave for a decade or more.
The issue is this:
Create a numbered list like:
1. A line that I'll want to copy and paste into another application
2. Another line that I'll want to copy and paste into another application (like putty unix commands)
When I select with the mouse "A line that I'll want to copy and paste into another application" and paste it in putty, it pastes:
"1. A line that I'll want to copy and paste into another application" which of course will cause an error because I did not select nor want the "1. "
I had tried the "ConvertNumbersToText" Word method and that sort of works, but it's a one way conversion. One can't easily go back to automatic numbering after converting to text, and doing the conversion also removes text attributes like "bold". I had also read that in some cases it removes numbers altogether. So, this was sort of useable if I made a copy of the original document and worked with the scratch document without text emphasis.
My next try was to just add a space to the beginning of every list line because when you do that it solves the problem and doesn't select the number, period and space as long as you don't also copy that space that you added to the beginning of the line. But then the answer emerged. Don't add a space; add a non-printing character...one that won't print and one that has no width. That is the "soft hyphen". This works fantastic so far.
So, I just search and replace the entire word document and add a soft hyphen to the beginning of every line. It shows no visual effect at all and line breaks are going to happen toward the end of line anyway, not the beginning.
To employ this, you can do a search and replace like below.
Search: ([!^13]{1,})
Replace: ^-\1
You must check the "Use Wildcards" checkbox under the "more" button in search and replace dialog
That will demonstrate how this works. Once you replace every line in your Word document with a soft hyphen "^-" at the start of line, you can now select the whole numbered line and paste it elsewhere without the stupid number, period and space as long as you use the right method to copy the line. And that is described under the "Caveats" below.
To make this more usable, you can create a macro. Definition below. Then to make it really useable, set that macro to an F-key
Sub AddSoftHyphen()
With ActiveDocument.Content.Find
.MatchWildcards = True
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([!^13]{1,})"
.Replacement.Text = "^-\1"
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
End Sub
Now add the macro to a shortcut key combination like Alt - F11
After composing a document using autonumbering, then at the end run this macro and click save.
Or, open an existing document and run the macro. You can either save or not save the changes, but if you do, there should be no noticeable difference in the way the document looks or behaves.
Caveats -
1. Using this method, it's best to have the Word Option "Display "Optional Hyphens" unchecked so that the soft hyphens are not visible on your screen. That is found at File, Options, Display, and uncheck the "Optional Hyphens" checkbox. You can enable it just to see if hyphens are in a file already, but it's easiest to use this method with them being invisible. And if you like them displayed, that's fine, but don't select that soft hyphen when you copy the item text, otherwise you end up getting the number, period, space again like you don't want.
The reason to keep those hyphens hidden is that if you don't have them displayed, it's easier to use the mouse to copy text and not have to try to avoid copying the hyphen character.
2. Don't use double and triple mouse click to copy a text line because it will also grab the hidden hyphen even if it's not being displayed. Use the mouse and click and drag.
3. To allow better control of click and drag when selecting with the mouse, go to File, Options, Advanced, and uncheck the "When selecting, automatically select entire word".
When that setting is checked, it gives you less control when selecting and can end up copying the soft hyphen characters.
4. When selecting the line with the mouse, don't select the return or blank space after the last character in a line. If you do, it will copy the list number like you don't want it to.
Hope that helps. Let me know if I missed something in this description.
The issue is this:
Create a numbered list like:
1. A line that I'll want to copy and paste into another application
2. Another line that I'll want to copy and paste into another application (like putty unix commands)
When I select with the mouse "A line that I'll want to copy and paste into another application" and paste it in putty, it pastes:
"1. A line that I'll want to copy and paste into another application" which of course will cause an error because I did not select nor want the "1. "
I had tried the "ConvertNumbersToText" Word method and that sort of works, but it's a one way conversion. One can't easily go back to automatic numbering after converting to text, and doing the conversion also removes text attributes like "bold". I had also read that in some cases it removes numbers altogether. So, this was sort of useable if I made a copy of the original document and worked with the scratch document without text emphasis.
My next try was to just add a space to the beginning of every list line because when you do that it solves the problem and doesn't select the number, period and space as long as you don't also copy that space that you added to the beginning of the line. But then the answer emerged. Don't add a space; add a non-printing character...one that won't print and one that has no width. That is the "soft hyphen". This works fantastic so far.
So, I just search and replace the entire word document and add a soft hyphen to the beginning of every line. It shows no visual effect at all and line breaks are going to happen toward the end of line anyway, not the beginning.
To employ this, you can do a search and replace like below.
Search: ([!^13]{1,})
Replace: ^-\1
You must check the "Use Wildcards" checkbox under the "more" button in search and replace dialog
That will demonstrate how this works. Once you replace every line in your Word document with a soft hyphen "^-" at the start of line, you can now select the whole numbered line and paste it elsewhere without the stupid number, period and space as long as you use the right method to copy the line. And that is described under the "Caveats" below.
To make this more usable, you can create a macro. Definition below. Then to make it really useable, set that macro to an F-key
Sub AddSoftHyphen()
With ActiveDocument.Content.Find
.MatchWildcards = True
.ClearFormatting
.Replacement.ClearFormatting
.Text = "([!^13]{1,})"
.Replacement.Text = "^-\1"
.Wrap = wdFindStop
.Execute Replace:=wdReplaceAll
End With
End Sub
Now add the macro to a shortcut key combination like Alt - F11
After composing a document using autonumbering, then at the end run this macro and click save.
Or, open an existing document and run the macro. You can either save or not save the changes, but if you do, there should be no noticeable difference in the way the document looks or behaves.
Caveats -
1. Using this method, it's best to have the Word Option "Display "Optional Hyphens" unchecked so that the soft hyphens are not visible on your screen. That is found at File, Options, Display, and uncheck the "Optional Hyphens" checkbox. You can enable it just to see if hyphens are in a file already, but it's easiest to use this method with them being invisible. And if you like them displayed, that's fine, but don't select that soft hyphen when you copy the item text, otherwise you end up getting the number, period, space again like you don't want.
The reason to keep those hyphens hidden is that if you don't have them displayed, it's easier to use the mouse to copy text and not have to try to avoid copying the hyphen character.
2. Don't use double and triple mouse click to copy a text line because it will also grab the hidden hyphen even if it's not being displayed. Use the mouse and click and drag.
3. To allow better control of click and drag when selecting with the mouse, go to File, Options, Advanced, and uncheck the "When selecting, automatically select entire word".
When that setting is checked, it gives you less control when selecting and can end up copying the soft hyphen characters.
4. When selecting the line with the mouse, don't select the return or blank space after the last character in a line. If you do, it will copy the list number like you don't want it to.
Hope that helps. Let me know if I missed something in this description.