MS Office Forum / Word / Programming / June 2007
Word 2003 "Not Responding" after Find and Replace
|
|
Thread rating:  |
RCHaynes - 07 Jun 2007 17:48 GMT Hi, I'm cross-posting with a vengeance attempting to solve a problem. I have a log file, that I'm trying to use macros to reformat and segregate into seperate files. All my subs except one work.
Sub ConvertParagraphs2LineFeeds() ' ' reformat all Paragraphs to Line Feed characters. ' Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find .Text = "^p" .Replacement.Text = "^l" .Forward = True .Wrap = wdFindContinue .MatchWildcards = False End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
When I step through it, everything works until I hit the End Sub statement. I can see in the doc that all the paragraphs have become linefeeds. But I can't get the focus back onto the doc. I've even waited for up to 30 minutes, to see if it just needed to finish repaginating or something. No matter what I do Word hangs. I have a growth in memory, but I never get past the 'Not Responding' in Task Manager until I end the process. I have the same reaction when I try to enter the ^p ^l in the Find and Replace interface from the Edit menu, so I am suspecting that Word is somehow skewed, not my macro. Anyone have any insight?
Helmut Weber - 07 Jun 2007 19:50 GMT Hi,
you cannot replace *all* paragraph marks by whatever, at least not without creating a new paragaph mark at the docs end, the doc-end-mark, which leads to an endless loop.
Sub Test004() Dim rDcm As Range Set rDcm = ActiveDocument.Range rDcm.End = rDcm.End - 1 With rDcm.Find .Text = "^p" .Replacement.Text = "^l" .Execute Replace:=wdReplaceAll End With End Sub
 Signature Greetings from Bavaria, Germany
Helmut Weber, MVP WordVBA
Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de"
RCHaynes - 07 Jun 2007 21:51 GMT Thanks muchly for the input! Alas, even though I can see in the document pane that all *but the last ^p* are now LineFeed characters (^l or ^11), I am still locking the application.
I am beginning to suspect either my install is corrupt, or the file is. I'll try again tomorrow with a fgresh file while I get support on the horn.
RCH
> Hi, > [quoted text clipped - 14 lines] > End With > End Sub Klaus Linke - 08 Jun 2007 05:06 GMT Hi,
I'm wondering if Word really hangs... Have you tried Ctrl+Pause to stop your macro (in case it's still running)? Maybe you've programmed some endless loop by accident.
Regards, Klaus
> Thanks muchly for the input! > Alas, even though I can see in the document pane that all *but the last [quoted text clipped - 5 lines] > I'll > try again tomorrow with a fgresh file while I get support on the horn. RCHaynes - 08 Jun 2007 14:03 GMT Thanks for the help. I don't think an endless loop is the issue, mostly because neither the orginal Sub nor the one Helmut proposed has a loo/Do While or other such control structure, though I suppose it is possible. I get the same problem when I use the Edit> Replace form the menu bar. I select all but the last ^p, and use the Find/Replace there. The document updates from paragraphs to linefeeds, except the final. I am notified that Word has made 60,096 replacements. I select the Close button on the Find and Replace dialog, and the application becomes non-responsive.
Is there a default 'int' counter that I need to change to a 'long' maybe? I have other such high number of occurences of replaces elsewhere in the document that do not cause an app hang, though there's a slight delay while Word repaginates the document.
> Hi, > [quoted text clipped - 14 lines] > > I'll > > try again tomorrow with a fgresh file while I get support on the horn. RCHaynes - 08 Jun 2007 15:58 GMT Well, it isn't a character count overflow. Looking closely at other successful find/replace actions, I have as many as 230,242 \t changes. If Word can handle that many changes, it can handle the 60K or so for this. Thanks for the assitance, I *will* beat this into submission eventually.
> Thanks for the help. > I don't think an endless loop is the issue, mostly because neither the [quoted text clipped - 29 lines] > > > I'll > > > try again tomorrow with a fgresh file while I get support on the horn. Klaus Linke - 08 Jun 2007 16:05 GMT Oops, just looked more carefully at your replacement:
If your document is of any greater length (and 60,096 paragraphs sounds like it), replacing all paragraph marks with manual line breaks is a very bad idea. Word deals very badly with long documents that have only a single paragraph.
What's the purpose?
Regards, Klaus
> Thanks for the help. > I don't think an endless loop is the issue, mostly because neither the [quoted text clipped - 33 lines] >> > I'll >> > try again tomorrow with a fgresh file while I get support on the horn. RCHaynes - 08 Jun 2007 16:28 GMT As a result of validating a test script, I get a log file displaying parameters used in the test, along with the server responses. The log file runs from 8-20MB. This is far too large for Notepad, and corporate limitations on software installations limit my choices (My preference would be for a progamming editor that didn't require the Word bells and whistles...) So, Rather than manually manipulate the file into something human readable, I'm trying to get it into a better form. So, my macro list does the following Strip all \n characters Strip all \r characters Strip all \t and ^9 characters (my doc has both methods of displaying a tab) Strip extraneous spaces (these Web pages being prone to the <tab><space><tab> etc despite having delivered a CSS for the page... invent the wheel and then pull a sledge. But I digress...) Strip out redundant transaction names. ^^^<All this works wonderfully well>^^^ Now I have all ^p, rather than linefeeds. I don't *want* 60,000+ paragraphs.
Somehow, I had gotten it into the format of using linefeeds and not blowing up on me. I then had macros that did the following
>Replace 'Starting Action " with a ^p, giving me a paragraph >>Loop through, selecting a Range based upon ActiveDocument.Paragraphs(1) End Loop when Selection.StoryLength=1 (represents the EOF ^p at the end of the doc), Open a NewDocument, Paste, Format, Name and Close, Return to the main doc
So, somehow in my development of this I at one point had it where each line ended in a LineFeed, and only about 54 Paragraph marks. I can't replicate that. During development, I had experimented with section breaks, page breaks and a few others until I stumbled upon the Paragraphs(1) concept for the slicing. At that time, the replacement of something to something worked.
Corporate Regulations prohibit me from using anything not part of 'the Corporate Image' without jumping through flaming hoops, submitting business needs in triplicate and sacrificing small animals, so I'm trying to make Word do this for me. Does that help?
Robin PS - Thanks for the help :)
> Oops, just looked more carefully at your replacement: > [quoted text clipped - 45 lines] > >> > I'll > >> > try again tomorrow with a fgresh file while I get support on the horn. Klaus Linke - 08 Jun 2007 19:27 GMT > Does that help? Yes, a bit... :-)
Two things:
-- Why don't you want 60.000 paragraphs, but don't mind 60.000 line breaks? I think you'll have to live with a lot of paragraph marks somehow, if you need to use Word. If you post some sample, and indicate where paragraph marks might sensibly be put in, it's very likely there is a simple wildcard replacement or two would do the trick.
-- Save as a Word document before you do anything to the file. Word's Find/Replace does not work properly if you open a text file and work directly on it. It'll miss matches if they span "block boundaries" (where a block has 256 bytes). So in most cases, 1 in 255 matches won't be found. That's very likely the explanation for your 54 misses. At least it was that way up to now, including Word 2003. Not sure about Wd2007.
good luck, Klaus
> As a result of validating a test script, I get a log file displaying > parameters used in the test, along with the server responses. [quoted text clipped - 111 lines] >> >> > try again tomorrow with a fgresh file while I get support on the >> >> > horn. RCHaynes - 08 Jun 2007 20:44 GMT In reverse order.... 2) The log file is copied, and pasted into a Word 'blank document', and saved under a filename.doc format. I don't try to use the tool unless it is in the right format.
1) Actually... I personally don't care how the lines are split! But, the final format of the log, even with all possible extraneous and redudndant information is removed still runs some 800 pages. This is too cumbersome, so with formatting explicitly entered here: Starting iteration 1.^l Starting action PSWLogin.^l (3): web_cache_cleanup was successful [MsgId: MMSG-26392^l ..... {several pages, still of the Login} (54): Notify: Parameter Substitution: parameter "VUserID" = "01"^l Ending action PSWLogin.^l ^p ClientChooser.^l (13): Notify: Transaction "02a_LongBeach" started.^l (15): Notify: Next row for parameter LoginServer = 1 [table = LoginServer].^l ..... {several pages, still of the Client Chooser} ... {and so on for 54 other logged actions}
Once I got it into this format, I was able to define and ; 'as best I can remember Set myRange = ActiveDocument.Paragraphs(1) Selection.Cut
This was the only method I had found for successfully slicing the file, and then select the chunk that would get cut and pasted into a NewDocument.
By all means, if you know of a better way to get the same result, I'm all ears!
Regards, and wishes for a great weekend to All! Robin Haynes
> > Does that help? > [quoted text clipped - 137 lines] > >> >> > try again tomorrow with a fgresh file while I get support on the > >> >> > horn. Russ - 09 Jun 2007 10:27 GMT You probably do not need to change all the small paragraphs to linefeeds to create separate large paragraphs to split a document. If you can define a unique pattern to use to split the document, you could insert a section break there to split the file into sections. Then you could cycle through each section and insert each into a separate new document, if that is what you need. Or you could insert titles with the "Heading" style and later view the document in Outline View, which allows you to expand and collapse what is under each "Heading" hierarchy.
You could search, for example, for the wildcard pattern: "Starting iteration [0-9]{1,}.^13" And insert a section break or heading before each matching found pattern.
> In reverse order.... > 2) The log file is copied, and pasted into a Word 'blank document', and [quoted text clipped - 175 lines] >>>>>>> try again tomorrow with a fgresh file while I get support on the >>>>>>> horn.
 Signature Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Graham Mayor - 09 Jun 2007 07:23 GMT I think I would sacrifice the small animals (and maybe a few large animals in suits employed solely to inhibit productivity) to get the software I wanted to do the job. The cost would be a fraction of what is being wasted both on trying to do something with inappropriate tools. But there again I always did like making waves. I wasn't called 'The Poisoned Pen' for nothing
:)
 Signature <>>< ><<> ><<> <>>< ><<> <>>< <>><<> Graham Mayor - Word MVP
My web site www.gmayor.com Word MVP web site http://word.mvps.org <>>< ><<> ><<> <>>< ><<> <>>< <>><<>
> As a result of validating a test script, I get a log file displaying > parameters used in the test, along with the server responses. [quoted text clipped - 94 lines] >>>>> try again tomorrow with a fgresh file while I get support on the >>>>> horn. RCHaynes - 18 Jun 2007 14:43 GMT Well, in other news... I was distracted from this project to fillin some man-month hours for something and wasn't able to pursue this.
I finally got a supportdesk guy down here, and after uninstalling and reinstalling MS Office, tries remoiving some of the KB updates. LO! The Find and Replace worked (preserving the EoF ^p as well)
Yes, a 'real' tool for parsing would be *vastly* preferable. But, corporate restrictions and all.... and, if I did use another tool, then it's 20 licenses for the other engineers in our group to use it. Now to figure out how to disinclude a list of 'titles' that I just want to exit the loop after cutting to poick up the next paste. Maybe I just want to go into the Do and paste it, and just close without saving when titles are such trivial things as 'null'
Thank yopu everyone for your help with this. I really appreciate all the time you offered to help me with my problem.
Robin Haynes
> I think I would sacrifice the small animals (and maybe a few large animals > in suits employed solely to inhibit productivity) to get the software I [quoted text clipped - 101 lines] > >>>>> try again tomorrow with a fgresh file while I get support on the > >>>>> horn.
|
|
|