Vba: the best way to repeat a macro indefinitely

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I have to scrape data from a website.
This website is constantly updated, so my activity of scraping must be carried out without interruption.
In vba terms: the macro must be repeated indefinitely, day and night.

Now, I've been using the following code:


VBA Code:
sub macro1

'....... activity of scraping (no problem in this part of the process)

call macro2

call macro1

end sub

macro2 is only needed to reset the data receiving sheet.


The problem is: the process stucks after a number of repetition (approximately from 5 to 10), probably at the end of the sub (it seems to me that the instruction "call macro1", at a certain point, is not processed).

Could somebody suggest me a safer way to repeat the macro?
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Please try this. As you have found out, calling the SUB from the same SUB eventually gets VBA tied into a knot. Using OnTime should prevent that because Macro1 will have had time to complete before calling it again,

VBA Code:
Sub macro1()

'....... activity of scraping (no problem in this part of the process)

Call macro2

Application.OnTime Now() + TimeSerial(0, 0, 10), "macro1", Now() + TimeSerial(0, 0, 20), True


End Sub
 
Upvote 0

Forum statistics

Threads
1,215,103
Messages
6,123,112
Members
449,096
Latest member
provoking

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top