selecting text II

L

Laura

once i asked in this forum, how could I select the text between 2 marks, The
marks were the first asteristic and the paragraph mark

I wrote an example;
with this text:
P*1.1*Antecedentes*Hasta la fecha actual*
x*a1* este es el anexo primero**17
A*a1* este es el apendice primero

and with the macro that Helmut Weber provided me, I was able to extract, for
example, this text: "1.1*Antecedentes*Hasta la fecha actual*"
I remembered the macro:
--------------------------------------------------
Sub Macro7()
Dim rTMp As Range
Set rTMp = selection.Paragraphs(1).Range
If rTMp.Characters(1) = "x" Then
rTMp.start = rTMp.start + 1
rTMp.End = rTMp.End - 1
rTMp.Select
' which is redundant
' for retrieving the text
MsgBox rTMp
Else
Exit Sub
End If
End Sub
--------------------------------------
it was ok, but now I need that the macro be more general. For example ->the
text between 2 asteristic.
i know to do it with the firs part (that only has a word), but when it has
more than a word, i don't know how to do it.
dim uno as string
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
With Selection.Find
.Text = "*"
.Replacement.Text = " * "
End With
Selection.Find.Execute Replace:=wdReplaceOne
uno = ActiveDocument.Paragraphs(3).Range.Words(2)

Can you help me please?thanks!
 
D

Dave Lett

Hi Laura,

Your sample
P*1.1*Antecedentes*Hasta la fecha actual*
x*a1* este es el anexo primero**17
A*a1* este es el apendice primero

reveals that only the first letter (i.e., "P") and "este es el apendice
primero" are the only things that are NOT between two * symbols. Is that
what you intended?

Dave
 
L

Laura

Hi Dave! and thanks for reply the post.

what i need to obtain from the macro (or procedure) is the text between the
* simbols.
perhaps, the solution maybe to place the cursor before the asteristic, and
then get the text's range until the next asteristic, I don't know...

Any idea will be welcome!
 
D

Dave Lett

Okay,

This is what you asked for:

Dim sString As String
With Selection
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Text = "\*(*)\*"
.MatchWildcards = True
Do While .Execute
Debug.Print Replace(Selection.Text, "*", "")
Selection.Characters.Last.Select
Selection.MoveLeft
Loop
End With
End With


HTH,
Dave
 
L

Laura

Dave
It works fine! I'm very grateful for your help. I'm a beginner programmer in
vba. And your help has been very important for me.

I hope some day I'm enough level to answer your questions
 

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

Similar Threads

selecting text 2
Text find/selection problem in textboxes 3
Search and replace predefined sets of strings? 9
hola ayudaaaaaa 0
pleaseeeeeeee 0
GotoBottom 1
sumatorias segun criterios desde tabla 0
zoonziiLLaaaa ! 0

Top