Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel Macro auto-refresh workbook based on user input time

Tags:

refresh

excel

vba

I use a lot of WEBSERVICE calls in my workbook, which is connectionless. Therefore, the only way to periodically refresh values is with a macro. To do so automatically upon workbook open and every 30 seconds thereafter, the following works great:

Dim TimeToRun

Sub auto_open()
Sheets("DataInput").Select
Sheets("DataInput").Range("A1").Activate
    Application.CalculateFull
    Call ScheduleWorkbookRefresh
End Sub

Sub ScheduleWorkbookRefresh()
    TimeToRun = Now + TimeValue("00:00:30")
    Application.OnTime TimeToRun, "WorkbookRefresh"
End Sub

Sub WorkbookRefresh()
    Application.CalculateFull
    Call ScheduleWorkbookRefresh
End Sub

Sub auto_close()
    Application.OnTime TimeToRun, "WorkbookRefresh", , False
End Sub

As usual, users claim the refresh interval of 30 seconds is somewhere between too short and too long. So, the idea is to let users fill in the interval they want in cell B9. However, there doesn't seem to be an acceptable way to put a cell number (or variable) into the TimeValue function.

Any ideas on how I might modify the macro to allow users to choose their own refresh interval, other than making the macro available for user edit (similar to handing a loaded gun, safety off, to a troop of chimpanzees)?

like image 972
HorseBeforeTheCart Avatar asked Jun 03 '26 11:06

HorseBeforeTheCart


1 Answers

Use TimeToRun = Now + TimeValue("00:00:" & Sheets("DataInput").Range("A1").Value)

like image 164
paul bica Avatar answered Jun 06 '26 03:06

paul bica



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!