Loop through and amend a lookup

O

Ocean

I have a document that has a macro that user clicks, and then it goes on to
internet locates a table, downloads it into Word and then formats it.
They are football tables. I can do one for say the League 1 and it collects
the data fine.
I want to now do it for all the 4 leagues automatically.
So for example the 4 strings
ie.navigate "Http//www.footyresults.com/league1.html
then "Http//www.footyresults.com/league2.html
then "Http//www.footyresults.com/league3.html
then "Http//www.footyresults.com/league4.html

The tables are the same each time - so it is just the look up that changes.
I know it is something to do with loops, but would appreciate a bit of
advise on how to best go about this ?
Any help would be appreciated.
Thanks
 
S

Shauna Kelly

Hi

When you say you have "a macro", do you mean you have one single big thing
that starts with Sub and ends with End Sub?

If so, what you need to do is to chop up that one big macro into several
smaller macros. At its simplest level, it might look something like this:

Sub UpdateAllFootyResults

GetFootyLeagueResults sWhichLeague:=
"Http//www.footyresults.com/league1.html"
GetFootyLeagueResults sWhichLeague:=
"Http//www.footyresults.com/league2.html"
'etc

End Sub

Sub GetFootyLeagueResults (sURL as string) as Word.Table
'Put here the code to look up the web page, paste in the table and
format it
End Sub

For more info, see
How to cut out repetition and write much less code, by using subroutines and
functions that take arguments
http://www.word.mvps.org/FAQs/MacrosVBA/ProcArguments.htm

Hope this helps.

Shauna Kelly. Microsoft MVP.
http://www.shaunakelly.com/word
 

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