Auto run Macro every nth minute

fredrerik84

Active Member
Joined
Feb 26, 2017
Messages
383
A couple of days ago the site where I get my currency from made some changes and killed my project :/
I'm just finished rewriting this. Earlier I had just web page import in excel which worked just fine , but now I have rewritten this as a web scraping project and I'm proud to say its working much better now.

So to my problem. I really would like my currencies script to be run automatically every nth minute which I can change depending on the mood :)

I made these global variables:
Rich (BB code):
Public RunWhen As Double
Public Const cRunWhat = "Exchangerates"  ' the name of the procedure to run
Public Const cRunIntervalSeconds = 2700  ' 45 min
And this code to auto run the script:

Rich (BB code):
Option Explicit


Sub xratetimer()
Dim wb As Worksheet
Set wb = ActiveWorkbook.sheets("Conversion")
Dim sheet As Worksheet
Set sheet = ActiveWorkbook.sheets("Data")
Dim timer As String
Dim triggertimer As String


timer = wb.Cells(3, "L")


If timer = "Startup" Then
   call StopTimer 
   Exit Sub
ElseIf timer = "Manual" Then
   call StopTimer
   Exit Sub
Else
    RunWhen = Now + TimeSerial(0, 0, cRunIntervalSeconds)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
    Schedule:=True
End If
End Sub


Sub StopTimer()
    On Error Resume Next
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
        Schedule:=False
End Sub


Sub updatenow()
Call StopTimer
Call Exchangerates
End Sub

So basically everything woks just fine now. But in my workbook sheet "Conversion" I have in Cell "L3" Auto update frequency selector. How can I integrate this into the global variable I have set as cRunIntervalSeconds ?

I have a list selector here where I want to be able to choose between Never, Startup , 1 min , 5 min, 10, min, 30, min , 1h , 2h, and so on

(also these values are stored in my sheet "Data" I was thinking vlookup to convert 1min to 60 sec , 2 min - 120 sec, like this

Updatetime
StartupStartup
ManualManual
2 min00:02
10 min00:10
15 min00:15
20 min00:20
25 min00:25
30 min00:30
45 min00:45
60 min01:00
90 min01:30
2 hour02:00
3 hour03:00
6 hour05:00
12 hour12:00

<tbody>
</tbody>


Was alot of info here hope anyone takes to time to help a little .. :)
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Sorry for the very long post , I think i have found an solution for my problem. I set this public empty: Public cRunIntervalSeconds

and it loads info in it on workbook open ,
 
Upvote 0

Forum statistics

Threads
1,215,214
Messages
6,123,660
Members
449,114
Latest member
aides

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