Deleting between certain srings

J

julian_m

Now i'm looking for a macro, which would delete whatever text between
certain tags, for instance

given this:

bla bla bla /* this piece
of text should be deleted,
no matter whether it is a
paragraph or not */ bla bla bla

after macro execution should be

bla bla bla bla bla bla

Note that , in this case, the tags are /* and */ , which are css/php/c
comments, that is what i need the macro for

tnx - jm
 
G

Greg

With all the examples you now have, are you at least attempting your
own code?

Try:

Sub ScratchMacro()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "/\* */\*"
.Forward = True
.Wrap = wdFindStop
.MatchWildcards = True
Do While .Execute
oRng.Delete
Loop
End With
End Sub
 
J

julian_m

Greg said:
With all the examples you now have, are you at least attempting your
own code?

You're right. I promise i'll try. It's just I'm a little bit confused
with VBA object model, but, again, I'll try ; )

tnx - jm
 
J

julian_m

.Text = "/\* */\*"

I changed this line to

.Text = "/* */"

....in order to be able to find both /* and */. I'm unsure why you wrote
"/\* */\*". I guess it has to do with wildcads, is it?

sdos - jm
 
J

julian_m

Greg said:
I read your example wrong. "/*/" is all you really need.


Hello. Yesterday, Greg provided me the following macro

Sub EliminarCSSComentarios()
Dim oRng As Range
Set oRng = ActiveDocument.Content
With oRng.Find
.ClearFormatting
.Text = "/* */"
'.Text = "/*/"
.Forward = True
.Wrap = wdFindStop 'para cuando se llega al final del documento
.MatchWildcards = True
'oRng.Select
'MsgBox "se encontró"
Do While .Execute
oRng.Select
MsgBox "encontro"
oRng.Delete
Loop
End With


Which supposedly should find every text between /* and */ , and delete
it. So, I tryied it starting whith this text


/* All this text should /be removed */
/* All this text /should be removed */
/* All this text should be /removed */

but the result was:

be removed ** All this text
removed */

....so I tried changing ".text" to .Text = "/* */", but it didn't work
either. The result was

slightly different, but not what I expected:

be removed *should be removed *removed */

It seems to me that the code is finding text between / and /, and not
between /* and */

Anyone could give me some hints about that ?

tnx - jm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top