Timer to run code every minute

grcshekar

New Member
Joined
Dec 11, 2019
Messages
17
Office Version
  1. 2010
Platform
  1. Windows
Hi,

I would like to run below query every one minute. May I please seek help on how to do it

Sub webquery()
dt = Format(Now, "ddmmyyyyhhmmss")
url = "https://www.amfiindia.com/spages/NAVAll.txt?t=" & dt
With Worksheets("NAV_RawFormat").QueryTables.Add(Connection:="url;" & url, Destination:=Worksheets("NAV_RawFormat").Range("A1"))
.Name = "AMFI Query"
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = False
.RefreshStyle = xlOverwriteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
.WebSingleBlockTextImport = False
.WebDisableDateRecognition = False
.WebDisableRedirections = False
.Refresh BackgroundQuery:=False
End With
End Sub
 

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Michael M

Well-known Member
Joined
Oct 27, 2005
Messages
20,029
Office Version
  1. 2016
  2. 2013
  3. 2007
Platform
  1. Windows
There may be a better way but try
AND
you might 1 minute MAY time out your webquery....you may have to extend the time depending on the net refresh speed
VBA Code:
Sub webquery()
dt = Format(Now, "ddmmyyyyhhmmss")
URL = "https://www.amfiindia.com/spages/NAVAll.txt?t=" & dt
With Worksheets("NAV_RawFormat").QueryTables.Add(Connection:="url;" & URL, Destination:=Worksheets("NAV_RawFormat").Range("A1"))
.Name = "AMFI Query"
.PreserveFormatting = True
.RefreshStyle = xlOverwriteCells
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.WebSelectionType = xlEntirePage
.WebFormatting = xlWebFormattingNone
.WebPreFormattedTextToColumns = True
.WebConsecutiveDelimitersAsOne = True
End With
Call startimer
End Sub
'=======================
Sub startimer()
    Application.OnTime Now + TimeValue("00:01:00"), "webquery"
End Sub
'======================
Private Sub Workbook_BeforeClose(Cancel As Boolean)
    Call StopTimer
End Sub
'======================
Sub StopTimer()
    On Error Resume Next
    Application.OnTime RunTime, "RefreshTime", Schedule:=False
    On Error GoTo 0
End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,127,098
Messages
5,622,682
Members
415,920
Latest member
ExcelNoob28

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
Top