Timer to run code every minute

grcshekar

New Member
Joined
Dec 11, 2019
Messages
19
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
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
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
 
Upvote 0
Solution

Forum statistics

Threads
1,224,829
Messages
6,181,219
Members
453,024
Latest member
Wingit77

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