muyBN
Fri Jun 02 15:41:01 CDT 2006
Dave, this looks good. Jean-Guy (in posts above) also suggested using ranges.
I'll work with what you've suggested and let you know. As I told him, I use
Selection all the time and haven't much experience with the Range object, but
it's time I start a-learnin' it.
BTW, following is my "SdnFmt" subroutine. It basically searches for
pre-defined formatted text without all the built-in parameters of the "With
Selection.Find".
Sub SdnFmt(strPassTxt As String)
With Selection.Find
.Text = strPassTxt
.Forward = True
.Wrap = wdFindStop
.MatchCase = False
.MatchWholeWord = False
.Format = True
End With
Selection.Find.Execute
End Sub
--
Bryan
"Dave Lett" wrote:
> Hi again,
>
> So, your routine
> 1) finds the @ symbol (bookmarks it) and moves one character at a time to
> the RIGHT while performing a check
> 2) selets the bookmark (i.e., the @ symbol), move one character at a time to
> the LEFT of the @ symbol while performing a check (and prefixes the new text
> to the email address)
> 3) after testing for a valid email address, you move the selection to the
> RIGHT so that it's at the very beginning of the email address.
> 4) You then run SdnFmt ("@") again (which I presume is finding the @ symbol)
>
> That LOOKS like and endless loop because it would select the next @ symbol
> in the document and the cursor is in front of the email address that you
> just parsed, so you would always be finding the same @ symbol. However, I
> don't know the details of SdnFmt ("@"), and if you say that it doesn't
> create an endless loop, I will defer to your hands-on experience with your
> routine(s).
>
> However, if you're really trying to optimize how well your routine performs,
> I would suggest that you use the range object to get your email address
> instead of the selection object. In fact, you MIGHT be able to use a
> wildcard search for email address (to get the whole address in the selection
> and avoid having to extend the selection to the left or right). Make a copy
> of one of the documents that has a lot of email addresses in it and see if
> the following could work:
>
> Dim oRng As Range
> With Selection.Find
> .ClearFormatting
> .Text = "[A-z0-9.]{2,}\@[A-z0-9.]{2,}"
> .MatchWildcards = True
> Do While .Execute
> Set oRng = Selection.Range
> If Right(oRng.Text, 1) = "." Then
> oRng.MoveEnd Unit:=wdCharacter, Count:=-1
> End If
> MsgBox oRng.Text
> Loop
> End With
>
> If this meets your needs, it will be a lot more efficient than what you
> currently have.
>
> HTH,
> Dave
>
> "muyBN" <muyBN@discussions.microsoft.com> wrote in message
> news:9B25BF2D-0710-49E4-99B8-F2B1306B42FC@microsoft.com...
> > Thanks, but the function to find e-mail is well-tested. The loop always
> > stops
> > as long as there is a space, paragraph, line break, semi-colon or comma
> > (code
> > shown below). I will, however, check more carefully for errors in other
> > loops. When I F8 through the whole thing (including function below), there
> > are no problems.
> >
> >
> >
> > Function jbGetEMail(strParaMark As String, strE As String) As String
> > Dim intCnt As Integer
> >
> > With Selection.Find
> > .ClearFormatting
> > .Font.Hidden = False
> > End With
> > DocHome
> > SdnFmt ("@")
> > BmkCreate ("strE")
> > With Selection
> > While .Find.Found And strE = ""
> > .MoveLeft
> > .MoveRight Extend:=wdExtend
> > While Selection <> " " And Selection <> Chr(13) And Selection
> > <>
> > Chr(11) And Selection <> Chr(10) And Selection <> "," And Selection <> ";"
> > strE = strE & Selection
> > .MoveRight
> > .MoveRight Extend:=wdExtend
> > Wend
> > BmkGoTo ("strE")
> > .MoveLeft
> > .MoveLeft Extend:=wdExtend
> > While Selection <> " " And Selection <> strParaMark And
> > Selection <> "," And Selection <> ";"
> > strE = Selection & strE
> > .MoveLeft
> > .MoveLeft Extend:=wdExtend
> > Wend
> > .MoveLeft
> > Sdn (strE)
> > If InStr(strE, ".") <> 0 And InStr(strE, "@") <> 0 Then
> > BmkCreate ("strE")
> > strE = Trim(Selection)
> > .Font.Hidden = True
> > Else
> > strE = ""
> > BmkDelete ("strE")
> > End If
> > .MoveRight
> > SdnFmt ("@")
> > Wend
> > End With
> > strE = Trim(strE)
> > If Right(strE, 1) = "." Then
> > strE = Left(strE, Len(strE) - 1)
> > End If
> > jbGetEMail = strE
> > End Function
> >
> > --
> > Bryan
> >
> >
> > "Dave Lett" wrote:
> >
> >> As Jean-Guy mentioned, It seems you are doing lots of text/string
> >> manipulations.
> >> Since you are apparently finding the @ symbol and extending the range of
> >> that in two directions inside some type of loop, I would want to make
> >> sure
> >> that the logic of the loop actually allows you to escape the loop (i.e.,
> >> make sure that the routine isn't stuck in an endless loop).
> >>
> >> Dave
> >>
> >>
> >> "Jean-Guy Marcil" <NoSpam@LeaveMeAlone> wrote in message
> >> news:eoZLUPnhGHA.3588@TK2MSFTNGP02.phx.gbl...
> >> > muyBN was telling us:
> >> > muyBN nous racontait que :
> >> >
> >> >> Thanks for your assistance.
> >> >>
> >> >> The Word version I'm using is 2003.
> >> >>
> >> >> What the macro is doing wouldn't really seem relevant here due to the
> >> >
> >> > Of course it is.
> >> > If all your macros were behaving that way, then I would agree.
> >> > But it seems that it is only the one macro that does that. So the
> >> > answer
> >> > is in the macro.
> >> >
> >> >> fact that it does its job fine once then the next time it doesn't;
> >> >> but regardless, I will post a description here. Be forewarned that it
> >> >> might be kind of complicated to follow; I come up with some things
> >> >> that others would never dream of (nor would they want to, for fear of
> >> >> nightmares).
> >> >>
> >> >> What I do is copy text from employment-related Web ads so I can apply
> >> >> for the positions advertised. I then have my macro extract certain
> >> >> data and place it into a Word table, then I convert it to records in
> >> >> Access, using the fields as variables in my cover letter and resume.
> >> >>
> >> >> For example, to find the title of the position being offered, I set
> >> >> up an array of search variables such as "position, job, title," etc.
> >> >> When each of these is found, whichever one has a colon (":") within a
> >> >> certain amount of characters after it, I will assume that the trimmed
> >> >> text after the colon, to the end of the paragraph, will be the job
> >> >> title.
> >> >>
> >> >> Another example is for the e-mail address, if found. Mr. Macro
> >> >> searches for the "@" sign. While it's found, the macro adds each
> >> >> character to the left and right of the @ to the variable string, as
> >> >> long as it's not a space, paragraph mark or line break.
> >> >
> >> > It seems you are doing lots of text/string manipulations.
> >> >
> >> > Are you using the Selection object?
> >> > If you are, then don't. Use a Range object instead.
> >> >
> >> > Also, are you using "ActiveDocument" or a document object set to the
> >> > target document.
> >> >
> >> > Finally, it looks as though you are manipulating IE and Access with the
> >> > Macro?
> >> >
> >> > How are you instantiating the Access (and/or IE) object(s)?
> >> >
> >> > Have you debugged the macro step by step until you find the line
> >> > preceding
> >> > the hang?
> >> > Try to do it often enough so that it hangs few times.
> >> > Is it always the same line of code?
> >> >
> >> > --
> >> > Salut!
> >> > _______________________________________
> >> > Jean-Guy Marcil - Word MVP
> >> > jmarcilREMOVE@CAPSsympatico.caTHISTOO
> >> > Word MVP site:
http://www.word.mvps.org
> >> >
> >>
> >>
> >>
>
>
>