View Single Post
 
Old 12-08-2023, 10:45 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 200
RobiNew is on a distinguished road
Default Separate strings in a text file

I have a text file with several sequences of this type:
<p class=NonNrPar align=center style='text-align:center;line-height:
normal'><img width=453 height=255 id="Immagine 1"
src="E_DIME_ORIG_file/image001.jpg"></p>
I'm trying to write a macro that will 1) find the string |<img .... ><| (eventually to be deleted); 2) return the string |width=and its digits|; 3) return the string |height=and its digits|.
The code here below doesn't work. Should I try Split? Can someone help? Thanks!
Code:
Sub ThreeStrings()
Dim oRng As Range
Set oRng = ActiveDocument.Range
With oRng.Find
        .Text = "<img width"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
While .Execute
oRng.MoveEndUntil Cset:="><"
MyString = oRng
MsgBox MyString '1. this one works
'oRng.Delete
oRng.Collapse wdCollapseStart
oRng.MoveEndUntil Cset:=" h", Count:=wdForward 'this doesn't work
VarWd = oRng
MsgBox VarWd
oRng.Move Unit:=wdCharacter, Count:=1
'oRng.Select
 oRng.Collapse wdCollapseEnd
oRng.MoveUntil oRng Like "^# " 'this doesn't work
VarHi = oRng
MsgBox VarHi
Wend
    End With
End Sub
Reply With Quote