Home |
Search |
Today's Posts |
#1
|
|||
|
|||
FormattingText, removing characters and keeping character formats.?
Unfortunately I have to a search and replace ( just removing characters
e.g. carriage returns etc .. ) on a table row by row .. sadly it's a long story why. The document itself contains one table per page and for some reason if you do a Row.Range.Find ( or even selection.Find ) the process get's slower and slower! I then had a look at using RegExp to perform the search and replace and tried it on formattedText ( and Selection.Text and Range.Text as a test ) and it was very fast but unfortunately it removes the formatting and seems to take the formatting of the first character item, i.e. I have 5 characters in my text 'hello', all of which are formatted differently h is is red, e is bold green etc ... if I remove 'ell' 'o' will take the format of 'h'. Is there any easy way to do this as at the moment I am going through FormattedText.Characters in code and removing the characters one at a time ( using for each ), which is still a lot faster and works but it seems a bit on the Cowboy side ;-) Is there any way to remove characters in a table row, keep the formatting for all characters that are left and not have to use the built in .Find .. search and replace functionality? ( as a side not anyone ever experienced it getting slower and slower ?) Thanks for any help you can give as I'm starting to loose it ;-) |
#2
|
|||
|
|||
Try inserting an UndoClear to speed things up. And possibly a wildcard
replace to delete the unwanted characters See the article "Finding and replacing characters using wildcards" at: http://word.mvps.org/FAQs/General/UsingWildcards.htm -- Hope this helps. Please reply to the newsgroup unless you wish to avail yourself of my services on a paid consulting basis. Doug Robbins - Word MVP "Stephen Gray" wrote in message ups.com... Unfortunately I have to a search and replace ( just removing characters e.g. carriage returns etc .. ) on a table row by row .. sadly it's a long story why. The document itself contains one table per page and for some reason if you do a Row.Range.Find ( or even selection.Find ) the process get's slower and slower! I then had a look at using RegExp to perform the search and replace and tried it on formattedText ( and Selection.Text and Range.Text as a test ) and it was very fast but unfortunately it removes the formatting and seems to take the formatting of the first character item, i.e. I have 5 characters in my text 'hello', all of which are formatted differently h is is red, e is bold green etc ... if I remove 'ell' 'o' will take the format of 'h'. Is there any easy way to do this as at the moment I am going through FormattedText.Characters in code and removing the characters one at a time ( using for each ), which is still a lot faster and works but it seems a bit on the Cowboy side ;-) Is there any way to remove characters in a table row, keep the formatting for all characters that are left and not have to use the built in .Find .. search and replace functionality? ( as a side not anyone ever experienced it getting slower and slower ?) Thanks for any help you can give as I'm starting to loose it ;-) |
#3
|
|||
|
|||
Many thanks Doug, even with the UndoClear the speed still degrades.
When I add the Row I then need to format it, and if I do this using the ..Find method the process begins to degrade (there is only one table per page not one massive table ) I posted the code on an earlier topic Basically the process is : If new page create table Add Row ( which is taken from another document and has characters in that need removing ) Apply the code to remove the chars .. which I posted on an earlier topic. http://groups.google.co.uk/group/mic...49ee4722432feb The weird thing is if I work on the same range, removing the characters by going through FormattedText.Characters there is no performance degradation as I go through the rows .. which doesn't make sense .. it's almost as if Word is holding onto something on ever search and replace where by it doesn't care if I "do it by hand". Most strange eh? Regards Steve |
#4
|
|||
|
|||
Hi again Stephen,
If you access the row by its index -- Row(i) -- you might try if doing a "For Each myRow in myTable.Rows" speeds things up. In case your table columns aren't formatted in different paragraph styles, and the table is simple (uniform = no merged cells...), you could convert the table to tab-delimited text, do your replacements, and convert it back to a table. Should you still have trouble, you might post some examples of the replacements you are doing, and perhaps the code you are currently using. Say to trim trailing whitespace, you could use Dim myCell As Cell Dim myRange As Range ' ... Set myRange = myCell.Range.Duplicate myRange.MoveEnd Unit:=wdCharacter, Count:=-1 ' exclude end-of-cell-marker myRange.Collapse (wdCollapseEnd) myRange.MoveStartWhile Cset:=ChrW(32) & Chr(9) & ChrW(160), Count:=wdBackward myRange.Delete Greetings, Klaus "Stephen Gray" schrieb im Newsbeitrag ups.com... Unfortunately I have to a search and replace ( just removing characters e.g. carriage returns etc .. ) on a table row by row .. sadly it's a long story why. The document itself contains one table per page and for some reason if you do a Row.Range.Find ( or even selection.Find ) the process get's slower and slower! I then had a look at using RegExp to perform the search and replace and tried it on formattedText ( and Selection.Text and Range.Text as a test ) and it was very fast but unfortunately it removes the formatting and seems to take the formatting of the first character item, i.e. I have 5 characters in my text 'hello', all of which are formatted differently h is is red, e is bold green etc ... if I remove 'ell' 'o' will take the format of 'h'. Is there any easy way to do this as at the moment I am going through FormattedText.Characters in code and removing the characters one at a time ( using for each ), which is still a lot faster and works but it seems a bit on the Cowboy side ;-) Is there any way to remove characters in a table row, keep the formatting for all characters that are left and not have to use the built in .Find .. search and replace functionality? ( as a side not anyone ever experienced it getting slower and slower ?) Thanks for any help you can give as I'm starting to loose it ;-) |
#5
|
|||
|
|||
Thanks Klause. I couldn;t do a for each as I was adding the rows, then
formatting them. I the end I did something that went through the collection of FormattedText characters .. seems to work fine. Thanks again for all you help. Regards Steve |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How do I lock portions of Word docs. while keeping foreign languag | Microsoft Word Help |