Reputation: 171
I'm trying to make a macro but I don't know where to start, I would like to hide some text between special chars like :
!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~ (including "space" char)
For example if I got a doc like this :
::00-58-96::Hello there
::00-58-97::This is a test
::00-58-98::Nothing else
::00-58-99::Good bye !
I would like to get this after the macro is executed :
Hello there
This is a test
Nothing else
Good bye !
The text between the
:: ::
has been eliminated (including the :::)
Another example:
>>>some%text_here>>>This is another example
>>>some%text"here>>>Thank you for reading
>>>some%text@here>>>I hope you will have
>>>some&text²here>>>A great day
And the output will be :
This is another example
Thank you for reading
I hope you will have
A great day
At first time I was thinking on use the "Find and replace text" feature but I think is too complex for this.
Any hint will be really helpful.
Thanks !
Upvotes: 0
Views: 315
Reputation: 13490
You don't need VBA for this - all you need is a single wildcard Find/Replace, where:
Find = ([!"#$%&'()*+,-./:;<=>\?@[\]^94_`{|}~]{2,})*\1
Then, depending on whether you want to delete or simply hide the found content, use:
Replace = nothing
or
Replace = ^&
with the 'Hidden' font property, respectively.
You could, of course, record the above as a macro.
Upvotes: 0
Reputation: 6654
This will Do:
Sub tst()
ActiveDocument.Range.Select ' You can remove this line and run macro after selecting the text in which you want the replacement. This line will select the entire document.
With Selection.Find
.MatchWildcards = True
.Text = "::*::"
.Replacement.Text = ""
.Execute Replace:=wdReplaceAll, Forward:=True, _
Wrap:=wdFindContinue
End With
End Sub
Pro: Cntrl + Z
will work to undo this, if it doesn't perform as intended.
Upvotes: 1