From: macropod on 12 Apr 2010 06:22 Hi Doug, On reflection, the count is the count of spaces replaced, not the number of tabs they've been replaced with. -- Cheers macropod [Microsoft MVP - Word] "Doug Robbins - Word MVP" <dkr(a)REMOVECAPSmvps.org> wrote in message news:uKombEi2KHA.1016(a)TK2MSFTNGP02.phx.gbl... > Hi Paul, > > While that code does limit the changes to the selected text, the count of > the replacements made is a bit odd. > > If there is one instance of two spaces, the count is 1 > One instance of three spaces, the count is 2 > and similar anomalies for other combinations of instances and spaces. > > -- > 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, originally posted via msnews.microsoft.com > > "macropod" <macropod(a)invalid.invalid> wrote in message > news:ujbJ2zh2KHA.2284(a)TK2MSFTNGP06.phx.gbl... >> Hi andreas, >> >> Try: >> Sub Andreas() >> Dim i As Integer >> With Selection >> i = .Characters.Count >> With .Find >> .ClearFormatting >> .Replacement.ClearFormatting >> .Text = " {2,}" >> .Replacement.Text = "^t" >> .Forward = True >> .Wrap = wdFindStop >> .Format = False >> .MatchCase = False >> .MatchWholeWord = False >> .MatchAllWordForms = False >> .MatchSoundsLike = False >> .MatchWildcards = True >> .Execute Replace:=wdReplaceAll >> End With >> MsgBox i - .Characters.Count & " replacements made" >> End With >> End Sub >> >> -- >> Cheers >> macropod >> [Microsoft MVP - Word] >> >> >> "andreas" <andreas.hermle(a)gmx.de> wrote in message >> news:f07e103a-b88a-4116-a61c-56c6ef3e1d4c(a)r27g2000yqn.googlegroups.com... >>> Dear Experts: >>> >>> below code is supposed to replace redundant spaces with tabstops just >>> within the selected paragraphs. Regrettably all the redundant spaces >>> within the whole document get worked on. >>> >>> How has the code to be changed to work only on the selection (the >>> selection for example could be only just one paragraph). >>> >>> Help is much appreciated. Thank you very much in advance. >>> >>> Regards, Andreas >>> >>> >>> >>> Sub SearchAndReplaceJustinSelectedParagraphs() >>> >>> Dim intcount As Long >>> Dim myRange As Range >>> >>> >>> intcount = 0 >>> Selection.Find.ClearFormatting >>> Selection.Find.Replacement.ClearFormatting >>> >>> Set myRange = Selection.Range >>> myRange.Select >>> >>> With myRange.Find >>> .Forward = True >>> .Wrap = wdFindContinue >>> .ClearFormatting >>> .Text = " {2;}" >>> .Replacement.Text = "^t" >>> .MatchWildcards = True >>> While .Execute(Replace:=wdReplaceOne) >>> myRange.Collapse wdCollapseEnd >>> intcount = intcount + 1 >>> Wend >>> End With >>> >>> MsgBox intcount >>> End Sub >
From: andreas on 13 Apr 2010 07:00 On Apr 12, 10:49 am, "macropod" <macro...(a)invalid.invalid> wrote: > Hi andreas, > > Try: > Sub Andreas() > Dim i As Integer > With Selection > i = .Characters.Count > With .Find > .ClearFormatting > .Replacement.ClearFormatting > .Text = " {2,}" > .Replacement.Text = "^t" > .Forward = True > .Wrap = wdFindStop > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchAllWordForms = False > .MatchSoundsLike = False > .MatchWildcards = True > .Execute Replace:=wdReplaceAll > End With > MsgBox i - .Characters.Count & " replacements made" > End With > End Sub > > -- > Cheers > macropod > [Microsoft MVP - Word] > > > > "andreas" <andreas.her...(a)gmx.de> wrote in messagenews:f07e103a-b88a-4116-a61c-56c6ef3e1d4c(a)r27g2000yqn.googlegroups.com... > > Dear Experts: > > > below code is supposed to replace redundant spaces with tabstops just > > within the selected paragraphs. Regrettably all the redundant spaces > > within the whole document get worked on. > > > How has the code to be changed to work only on the selection (the > > selection for example could be only just one paragraph). > > > Help is much appreciated. Thank you very much in advance. > > > Regards, Andreas > > > Sub SearchAndReplaceJustinSelectedParagraphs() > > > Dim intcount As Long > > Dim myRange As Range > > > intcount = 0 > > Selection.Find.ClearFormatting > > Selection.Find.Replacement.ClearFormatting > > > Set myRange = Selection.Range > > myRange.Select > > > With myRange.Find > > .Forward = True > > .Wrap = wdFindContinue > > .ClearFormatting > > .Text = " {2;}" > > .Replacement.Text = "^t" > > .MatchWildcards = True > > While .Execute(Replace:=wdReplaceOne) > > myRange.Collapse wdCollapseEnd > > intcount = intcount + 1 > > Wend > > End With > > > MsgBox intcount > > End Sub- Hide quoted text - > > - Show quoted text - Hi Paul, it is working fine. Thank you very much. As Doug said, this counting has some restrictions. But I do not mind, I am glad to have an alternative code for my problem. Thank you very much for your professional help. Regards, Andreas
From: macropod on 13 Apr 2010 07:30 Hi andreas, If you don't need the tabs counter, you'll also find my code much faster with a large document. -- Cheers macropod [Microsoft MVP - Word] "andreas" <andreas.hermle(a)gmx.de> wrote in message news:c9419371-fbc0-425e-96cd-8fe4898a5559(a)r18g2000yqd.googlegroups.com... On Apr 12, 10:49 am, "macropod" <macro...(a)invalid.invalid> wrote: > Hi andreas, > > Try: > Sub Andreas() > Dim i As Integer > With Selection > i = .Characters.Count > With .Find > .ClearFormatting > .Replacement.ClearFormatting > .Text = " {2,}" > .Replacement.Text = "^t" > .Forward = True > .Wrap = wdFindStop > .Format = False > .MatchCase = False > .MatchWholeWord = False > .MatchAllWordForms = False > .MatchSoundsLike = False > .MatchWildcards = True > .Execute Replace:=wdReplaceAll > End With > MsgBox i - .Characters.Count & " replacements made" > End With > End Sub > > -- > Cheers > macropod > [Microsoft MVP - Word] > > > > "andreas" <andreas.her...(a)gmx.de> wrote in messagenews:f07e103a-b88a-4116-a61c-56c6ef3e1d4c(a)r27g2000yqn.googlegroups.com... > > Dear Experts: > > > below code is supposed to replace redundant spaces with tabstops just > > within the selected paragraphs. Regrettably all the redundant spaces > > within the whole document get worked on. > > > How has the code to be changed to work only on the selection (the > > selection for example could be only just one paragraph). > > > Help is much appreciated. Thank you very much in advance. > > > Regards, Andreas > > > Sub SearchAndReplaceJustinSelectedParagraphs() > > > Dim intcount As Long > > Dim myRange As Range > > > intcount = 0 > > Selection.Find.ClearFormatting > > Selection.Find.Replacement.ClearFormatting > > > Set myRange = Selection.Range > > myRange.Select > > > With myRange.Find > > .Forward = True > > .Wrap = wdFindContinue > > .ClearFormatting > > .Text = " {2;}" > > .Replacement.Text = "^t" > > .MatchWildcards = True > > While .Execute(Replace:=wdReplaceOne) > > myRange.Collapse wdCollapseEnd > > intcount = intcount + 1 > > Wend > > End With > > > MsgBox intcount > > End Sub- Hide quoted text - > > - Show quoted text - Hi Paul, it is working fine. Thank you very much. As Doug said, this counting has some restrictions. But I do not mind, I am glad to have an alternative code for my problem. Thank you very much for your professional help. Regards, Andreas
First
|
Prev
|
Pages: 1 2 Prev: I need Help on Microsoft Word! ASAP!!! Next: Cropping images with VBA |