![]() |
|
#1
|
|||
|
|||
![]()
Thank you, Vivka! Your code leaves everything unchanged. But what I need is not to highlight all instances of 'width=' and 'height=' followed by three-digit numbers.
As I suggested in the original post, 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 code that will 1) Find part of the above string: from <img to ><; 2) create a variable that contains the string width=### in the Found string; 3) create a variable that contains the string height=### in the Found string; 4) Delete the Found string: from <img to ><. Hope someone can help. Thanks! |
#2
|
|||
|
|||
![]()
I managed to make it work correctly, provisionally on a single instance of the text mentioned above.
Perhaps someone can make it less clumsy. 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 .MatchWildcards = False While .Execute oRng.MoveEndUntil Cset:="><" VarStrg1 = oRng 'MsgBox VarStrg1 oRng.Collapse oRng.MoveEndUntil Cset:=" " oRng.Move Unit:=wdCharacter, Count:=2 oRng.MoveEndUntil Cset:=" " VarWd = oRng 'MsgBox VarWd oRng.Move Unit:=wdCharacter, Count:=2 oRng.MoveEndUntil Cset:=" " VarHi = oRng 'MsgBox VarHi Set oRng = ActiveDocument.Range With oRng.Find .Text = "<img width" .Replacement.Text = "" .Forward = False .Wrap = wdFindStop .Format = False .MatchWildcards = False .Execute End With oRng.MoveEndUntil Cset:="><" oRng.Delete Goto End Wend End With End: End Sub |
#3
|
|||
|
|||
![]()
As a simple variant:
Code:
Sub Test() Dim oRng As range Dim vWd As Variant Dim vHi As Variant Set oRng = ActiveDocument.range With oRng.Find .ClearFormatting .Replacement.ClearFormatting .text = "width=^#^#^#" .Replacement.text = "" .MatchWildcards = False .Forward = True .Wrap = wdFindStop If .Execute Then vWd = oRng End With Set oRng = ActiveDocument.range With oRng.Find .text = "height=^#^#^#" If .Execute Then vHi = oRng End With With ActiveDocument.range.Find .text = "\<" & "img width" & "*" & "\>\<" .MatchWildcards = True .Execute Replace:=wdReplaceAll End With MsgBox vWd & vbCr & vHi lbl_Exit: Set oRng = Nothing End Sub |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to hide/delete slides based on keyword in a separate text file based on AND|OR condition? | rupd911 | PowerPoint | 0 | 02-22-2021 08:22 AM |
![]() |
commissarmo | Word VBA | 3 | 03-14-2015 12:53 AM |
![]() |
officeboy09 | Word | 6 | 09-26-2014 05:15 PM |
![]() |
subodhgupta | Word | 4 | 05-22-2014 03:34 AM |
![]() |
vikrantkale | Word | 1 | 03-28-2011 06:13 PM |