(edit: On subsequent edit, the poster declared that the problem had been solved and had been due to a spelling error then deleted the entire question text. Text restored with addition of this comment)
I have 2 macros that i need to scheduled:
Macro1 “GetData” – this needs to run every 35mins – to retrieve data from my DB.
Macro2 “RefreshData” – this needs to run every 1min after GetData is complete – to update my data.
I have tried:
Private Sub workbook_open()
Application.OnTime Now + TimeValue("00:35:10"), "GetData"
Application.OnTime Now + TimeValue("00:01:00"), "RefreshData"
End Sub
However, i am presented with:
“Cannot run the macro “c:\document and settings\alex\desktop\data.xlsm’!GetData’/ The macro may not be available in this workbook or all macro’s may be disabled”
Sub GetData ()
'' GetData ///////////////////////////////////////////////////////////////////////
Dim sh1 As Worksheet, data As Worksheet
Set sh1 = Worksheets("Sheet1")
Set data = Workbooks.Open(Filename:="C:\Documents and Settings\alex\Desktop\source.XLS"). _
Worksheets("Report 1")
Sheets("Report 1").Select
Set Rng = Sheets("Report 1").Range("A2:K350")
Selection.Copy
sh1.Activate
Rng.SpecialCells(xlCellTypeVisible).Copy Destination:=Sheets("Sheet1").Range("A2")
portfolioName.Activate
ActiveWorkbook.Close
End Sub
Sub RefreshData()
MsgBox ("-- Update every 1min --")
End Sub
Any help appreciated.
— Update ——-
I have now created a separate GetData module:
Private Sub workbook_open()
Application.OnTime Now + TimeValue("00:35:10"), "GetData"
'Application.OnTime Now + TimeValue("00:01:00"), "RefreshData"
End Sub
Public Sub GetData()
'' GetData ///////////////////////////////////////////////////////////////////////
....
....
End Sub
Still receive same error..
— Update——
Ok, within Sheet1 i have:
Public Sub workbook_open()
Application.OnTime Now + TimeValue("00:35:10"), "GetData"
'Application.OnTime Now + TimeValue("00:01:00"), "RefreshData"
End Sub
I have now Insert > Module and renamed the module to GetData
Within that GetData module i have:
Public Sub GetData()
'' GetData ///////////////////////////////////////////////////////////////////////
....
....
End Sub
Any comments welcome
OnTime requires the referenced macro to be in a standard module. The sub must also be public, which is default for a module. Insert a module, and move GetData and RefreshData into it.