Hi
I'm trying to extract multiple instances of part of a URL from the source code of a web page.
All these parts start with the same text but then end with a numeric string (representing the ID number for a round of golf).
Ultimately I'm after just a list of the ID numbers but for now the macro I'm trying to write should
[ol 1]
[li]Select all the text[/li]
[li]Find the first/next instance of "/golfers/score.php?id="[/li]
[li]Ctrl+Shift select to the right (to additionally select the ID number)[/li]
[li]Add that selection to a variable (which I'm delimiting/separating by a ~)[/li]
[li]Repeat from Step 2 until the last instance of the text is found[/li]
[/ol]
(What I'll then do is delete all the text so I have a blank document, then paste in the variable I've built up in the macro then remove all the remaining unwanted text)
Here's the code I have so far:
So the strIDs variable will end up looking something like
However, all that happens when I step through the code is the 'Do Until Selection.Find.Found = False' line is selected but then the code goes to 'End Sub'.
Clearly I'm missing something pretty obvious. I'm hoping so...
BTW, I'm using Word 2010 but I can't guarantee what version of Word my target audience members will have.
JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]
I'm trying to extract multiple instances of part of a URL from the source code of a web page.
All these parts start with the same text but then end with a numeric string (representing the ID number for a round of golf).
Ultimately I'm after just a list of the ID numbers but for now the macro I'm trying to write should
[ol 1]
[li]Select all the text[/li]
[li]Find the first/next instance of "/golfers/score.php?id="[/li]
[li]Ctrl+Shift select to the right (to additionally select the ID number)[/li]
[li]Add that selection to a variable (which I'm delimiting/separating by a ~)[/li]
[li]Repeat from Step 2 until the last instance of the text is found[/li]
[/ol]
(What I'll then do is delete all the text so I have a blank document, then paste in the variable I've built up in the macro then remove all the remaining unwanted text)
Here's the code I have so far:
Code:
Sub GetIDs()
'
' GetIDs Macro
'
'
Dim strIDs As String
Selection.WholeStory
Selection.Find.ClearFormatting
Do Until Selection.Find.Found = False
With Selection.Find
.Text = "/golfers/score.php?id="
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
'Additionally select the next word, which is the unique ID number
Selection.MoveRight Unit:=wdWord, Count:=1, Extend:=wdExtend
'Add the selection to the strIDs variable
strIDs = strIDs & Selection & "~"
Loop
End Sub
So the strIDs variable will end up looking something like
Code:
/golfers/score.php?id=12345~/golfers/score.php?id=678912~/golfers/score.php?id=3456789~/golfers/score.php?id=1234567
However, all that happens when I step through the code is the 'Do Until Selection.Find.Found = False' line is selected but then the code goes to 'End Sub'.
Clearly I'm missing something pretty obvious. I'm hoping so...
BTW, I'm using Word 2010 but I can't guarantee what version of Word my target audience members will have.
JJ
[small][purple]Variables won't. Constants aren't[/purple]
There is no apostrophe in the plural of PC (or PST, or CPU, or HDD, or FDD, or photo, or breakfast...and so on)[/small]