saphire99
12-20-2015, 05:33 AM
Hello,
to all again. I hope every one is having a great relaxing weekend.
I have come back to seek some advice on a regex problem - I assume.
My document has these website code lines hidden somewhere. I need to copy and paste 3 words to the left between some quote marks, and remove the spaces.
Here is an example:
<a href="# "> 1.2 Science Exam - 2015 Progress </a>
<a href="# "> 5.5 Algebra Equations - 2015 Progress </a>
End Result
<a href="#1.2ScienceExam"> 1.2 Science Exam - 2015 Progress </a>
<a href="#5.5AlgebraEquations"> 5.5 Algebra Equations - 2015 Progress </a>
My document has a lot of these hidden somewhere - as you can imagine I have to search and find these little lines.
Then for each one copy and paste to the left - before you know it - I am getting tired fast, as I have lots more in my folder that need the same yikes. :fright:
I recorded a macro - all it spewed up was copy paste and move back wards - it was as good as a lemon in winter.
My Attempt
Dim StrOld As String, StrNew As String
Dim RngFind As Range, RngTxt As Range, i As Long
StrOldRegEx = "<ahref \b[^>]*>(.*?)</a> "
StrOldRegEx = " <a href="# "> * </a> " ' Another try
Set RngTxt = Selection.Range
For i = 0 To UBound(split(StrOld, ","))
Set RngFind = RngTxt.Duplicate
With RngFind.Find
While .Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=4
Selection.TypeBackspace
Selection.MoveLeft Unit:=wdCharacter, Count:=7
Selection.TypeBackspace
Selection.Copy
Selection.PasteAndFormat (wdFormatOriginalFormatting)
I wish the word macro recorder was more helpful - so i could work out how to search for things and then perform an action.
Any help really appreciated
thank you in advance to the great experts:bow:
Saphire
to all again. I hope every one is having a great relaxing weekend.
I have come back to seek some advice on a regex problem - I assume.
My document has these website code lines hidden somewhere. I need to copy and paste 3 words to the left between some quote marks, and remove the spaces.
Here is an example:
<a href="# "> 1.2 Science Exam - 2015 Progress </a>
<a href="# "> 5.5 Algebra Equations - 2015 Progress </a>
End Result
<a href="#1.2ScienceExam"> 1.2 Science Exam - 2015 Progress </a>
<a href="#5.5AlgebraEquations"> 5.5 Algebra Equations - 2015 Progress </a>
My document has a lot of these hidden somewhere - as you can imagine I have to search and find these little lines.
Then for each one copy and paste to the left - before you know it - I am getting tired fast, as I have lots more in my folder that need the same yikes. :fright:
I recorded a macro - all it spewed up was copy paste and move back wards - it was as good as a lemon in winter.
My Attempt
Dim StrOld As String, StrNew As String
Dim RngFind As Range, RngTxt As Range, i As Long
StrOldRegEx = "<ahref \b[^>]*>(.*?)</a> "
StrOldRegEx = " <a href="# "> * </a> " ' Another try
Set RngTxt = Selection.Range
For i = 0 To UBound(split(StrOld, ","))
Set RngFind = RngTxt.Duplicate
With RngFind.Find
While .Find.Execute
Selection.MoveLeft Unit:=wdCharacter, Count:=4
Selection.TypeBackspace
Selection.MoveLeft Unit:=wdCharacter, Count:=7
Selection.TypeBackspace
Selection.Copy
Selection.PasteAndFormat (wdFormatOriginalFormatting)
I wish the word macro recorder was more helpful - so i could work out how to search for things and then perform an action.
Any help really appreciated
thank you in advance to the great experts:bow:
Saphire