Pwyll2
04-06-2015, 06:56 PM
Hello
I don't know much about VBA and I made a macro in Word with the Recorder Function. But I need to make a loop and I've no idea how to do that, and I don't understand what is explained on websites about VBA... It's always like Greek to me.
Basically, my macro is meant to do this:
<a name="">blablablah</a>
should become
<a name="blablablah">blablablah</a>
ie. what is between the tags should be copied and pasted between the " " in the tag just before. And this in every case with <a name="">TEXT</a>
until the end of the document.
Here is my macro:
Sub Ernault2_ancre_entree()
'
' Ernault2_ancre_entree Macro
' Macro enregistrée le 07/04/2015 par Pwyll2
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\<a name=\""\""\>"
.Replacement.Text = "</b>"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*\<\/a\>"
.Replacement.Text = "</b>"
.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:=4, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Where should I write Loop and other things so that the macro does the task until the end of the document?
Thanks a lot in advance!
I don't know much about VBA and I made a macro in Word with the Recorder Function. But I need to make a loop and I've no idea how to do that, and I don't understand what is explained on websites about VBA... It's always like Greek to me.
Basically, my macro is meant to do this:
<a name="">blablablah</a>
should become
<a name="blablablah">blablablah</a>
ie. what is between the tags should be copied and pasted between the " " in the tag just before. And this in every case with <a name="">TEXT</a>
until the end of the document.
Here is my macro:
Sub Ernault2_ancre_entree()
'
' Ernault2_ancre_entree Macro
' Macro enregistrée le 07/04/2015 par Pwyll2
'
Selection.Find.ClearFormatting
With Selection.Find
.Text = "\<a name=\""\""\>"
.Replacement.Text = "</b>"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.Find.ClearFormatting
With Selection.Find
.Text = "*\<\/a\>"
.Replacement.Text = "</b>"
.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:=4, Extend:=wdExtend
Selection.Copy
Selection.MoveLeft Unit:=wdCharacter, Count:=3
Selection.PasteAndFormat (wdPasteDefault)
End Sub
Where should I write Loop and other things so that the macro does the task until the end of the document?
Thanks a lot in advance!