![]() |
|
#1
|
|||
|
|||
|
Hi guys
I wanted to repeat/run this macro multiple times at a time. Code:
Sub get_irf fnf()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(\<irf fnf=)(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)(*)^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(\<irf fnfr=)(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & _
"/\>)-(\<)irf fnf=(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.HomeKey Unit:=wdStory
End Sub
Thanks Ganesan. G Last edited by macropod; 12-07-2018 at 03:17 PM. Reason: Added code tags |
|
#2
|
||||
|
||||
|
Please wrap your code with code tags - Thx
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
|
#3
|
|||
|
|||
|
Code:
Sub get_irf fnf()
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(\<irf fnf=)(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)(*)^13"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdStory
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "(\<irf fnfr=)(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & _
"/\>)-(\<)irf fnf=(" & ChrW(8220) & _
"[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)"
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.HomeKey Unit:=wdStory
End Sub
|
|
#4
|
||||
|
||||
|
Ok ( you could have done it in the original post which can be edited up to 24 hrs after the first edit)
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post |
|
#5
|
||||
|
||||
|
ganesang: When posting code, please use the code tags and apply them to formatted code. Otherwise, your code loses much of whatever structure it had. See my edit to your original post and compare it with your post #3 in this thread.
As for the question itself, it's not apparent why you'd want to run the same macro multiple times, since the use of '.Wrap = wdFindContinue' means all instances of whatever you're trying to replace should be processed on the first execution. As it is, your code is quite inefficient; you review the code you were provided in https://www.msofficeforums.com/word-...tml#post134040 for indications as to how your code's efficiency could be improved. Consider, too, https://www.msofficeforums.com/word-...tween-two.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#6
|
||||
|
||||
|
What is the point of running it more than once on the same file?
You can create another macro to run a macro multiple times. Code:
Sub DeJaVu()
Dim i as integer
For i = 1 to 10
MyMacroName
Next i
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#7
|
|||
|
|||
|
Quote:
Thanks for info about the code formatting. I can use it in future. Actually, i have recorded the macro which needs to be done Find the first set of value (using first willd card) from the end of document and cut it and replace at the first set of value (from first finding row using second wildcard) from the table. I have recorded the macro this way, but if have 40 replacements i have to run this macro 40 times manually. That's why asking to run macro until first wild card value false. Please let me know if not clear. Thanks |
|
#8
|
|||
|
|||
|
Quote:
Thanks for the reply. Please see my response to why i have run this macro multiple times. |
|
#9
|
||||
|
||||
|
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#10
|
|||
|
|||
|
Hi Paul
Please find the attached which i have run manually for each item. |
|
#11
|
||||
|
||||
|
I also think we need to see the context and reason for what you are trying to achieve. Looking at your code, it appears like it might be rewritten to loop along the following lines.
Code:
Sub get_irf_fnf()
Dim s1 As String, s2 As String
s1 = "(\<irf fnf=)(" & ChrW(8220) & "[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)(*)^13"
s2 = "(\<irf fnfr=)(" & ChrW(8220) & "[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)-(\<)irf fnf=(" & ChrW(8220) & "[A-Z 0-9]{1,}" & ChrW(8221) & "/\>)"
Selection.HomeKey Unit:=wdStory
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = s1
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
Do While .Execute = True
Selection.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
Selection.Cut
Selection.HomeKey Unit:=wdStory
.Text = s2
.Execute
Selection.PasteAndFormat (wdFormatOriginalFormatting)
Selection.HomeKey Unit:=wdStory
.Text = s1
Loop
End With
End Sub
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
#12
|
|||
|
|||
|
Thanks much!!! Guessed
I think this what i want to workout. Great!! thanks |
|
#13
|
||||
|
||||
|
Having seen what you're trying to do, it's apparent the end result is much different from what you sought in: https://www.msofficeforums.com/word-...nd-values.html. Rather, it seems that the current problem is a result of your inadequate problem description there; almost exactly the same code could have been used.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#14
|
|||
|
|||
|
Hi Paul
I have split in to the two process which is very easier for me as gmayor said lots of code involved in the previous single process. But the end result is fine what i expected exactly. thanks |
|
#15
|
||||
|
||||
|
Try:
Code:
Sub Demo()
Application.ScreenUpdating = False
Dim StrPfx As String, StrSfx As String, StrMid As String, StrTmp As String
Dim i As Long, j As Long, k As Long
StrPfx = "\<irf fnf=“": StrSfx = "”/\>"
With ActiveDocument.Range
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "(" & StrPfx & "[A-Z]@)[0-9]@" & StrSfx & "-\1[0-9]@" & StrSfx
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchWildcards = True
.Execute
End With
Do While .Find.Found
StrTmp = Split(Split(.Text, Replace(StrSfx, "\", ""))(0), "“")(1)
StrMid = StrTmp
For i = 1 To Len(StrTmp)
If Right(StrMid, 1) Like "[0-9]" Then
StrMid = Left(StrMid, Len(StrMid) - 1)
End If
Next
i = CLng(Replace(StrTmp, StrMid, ""))
StrTmp = Split(Split(.Text, Replace(StrSfx, "\", ""))(1), "“")(1)
StrMid = StrTmp
For j = 1 To Len(StrTmp)
If Right(StrMid, 1) Like "[0-9]" Then
StrMid = Left(StrMid, Len(StrMid) - 1)
End If
Next
j = CLng(Replace(StrTmp, StrMid, ""))
StrTmp = ""
For k = i To j
StrTmp = StrTmp & StrPfx & StrMid & k & StrSfx & Chr(11)
Next
StrTmp = Replace(StrTmp, "\", "")
.Text = Left(StrTmp, Len(StrTmp) - 1)
.Collapse wdCollapseEnd
.Find.Execute
Loop
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Mail Merge Repeat Record a certain number of times
|
stacey_e | Mail Merge | 7 | 07-07-2023 01:27 AM |
| Repeat macro until no more fields | ChrisJ83 | Word VBA | 2 | 01-20-2016 04:55 AM |
Print Format - Repeat Text From a Cell on Multiple Pages
|
ChristopherHughes | Excel | 1 | 12-07-2014 08:31 PM |
How to repeat multiple .jpg's over again in Custom Slide show
|
pbyrescue | PowerPoint | 1 | 04-03-2014 12:40 PM |
| Repeat formula 5 times and repeat? | Jenny345 | Excel | 4 | 06-14-2013 04:37 PM |