Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2006

Tip: Looking for answers? Try searching our database.

Deleting between certain srings

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
julian_m - 23 Feb 2006 15:55 GMT
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
Greg - 23 Feb 2006 16:46 GMT
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
julian_m - 23 Feb 2006 17:19 GMT
> 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
julian_m - 23 Feb 2006 17:36 GMT
>   .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
Greg - 23 Feb 2006 21:15 GMT
I read your example wrong.  "/*/" is all you really need.
julian_m - 24 Feb 2006 01:36 GMT
> 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
Greg Maxey - 24 Feb 2006 01:55 GMT
Try this as the find string:

/\*?{1,}\*/

Signature

Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

>> I read your example wrong.  "/*/" is all you really need.
>
[quoted text clipped - 44 lines]
>
> tnx - jm

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.