Change the URL + 1 in a loop

Hi, is it possible to change the end of the url+1 in a loop? For example if the url ends 0002 it should change to 0003 and then to 0004 and so on. Is it possible to execute other actions between the changes, like copy something or so?

Thank you

i'd try something along these lines:

Is the number at the end of the URL always going to be 4 digits? You could read the format of the variable from the regular expression and match the format if it would vary, but if you know it's always going to be the same, specifying the format works, like i did here. Someone smarter than me can probably do this in less steps, but hope this helps!

Hi, thank you for your reply. I searched the forums and it may be that it is easier to collect all urls in a file and then use the action "for each".

ah yeah, i didn't know if you were generating new URLs for an API call or something, but if you are using existing URLS, then I agree generating a list and using a for loop would be best!

The approach you'll take will depend on what you need to do. If you've a "static" list of URLs to open, a hand-written Collection of URLs and a "For Each" is easy to do -- and easy to understand when you come back to it later!

If you don't know in advance how many pages you'll need to get every time you run the macro you'll need a different loop. How you do that will depend on how the URLs change -- your example is great if you can determine the "start" and "stop" numbers for the URLs or, if you only know the "start" number, you could loop until the latest attempt returns a "404 -- URL not found".

You can even combine the two approaches, using a loop (or multiple loops!) to build your URL Collection, then "For Each"ing that collection later. That would be useful if your "URL building" is complex because separating the "building" from the "getting" makes your macro more understandable and maintainable.

If you can give a more extended example of what you want to do (an URL can be used in many things, not just browsers!) and how you want to process things between URLs, then I'm sure people can come up with some examples for you.

1 Like