I'm facing a bit of a bind with my macro in VBA Excel. Previously I have a macro that can extract data from another closed Excel sheet (or one that is opened in a different instance). I placed the code in 'ThisWorkbook' in VBA:
Option Explicit
Private Sub Workbook_Open()
Call ReadDataFromCloseFile
End Sub
Sub ReadDataFromCloseFile()
On Error GoTo ErrHandler
Application.ScreenUpdating = False
Dim src As Workbook
' OPEN THE SOURCE EXCEL WORKBOOK IN "READ ONLY MODE".
Set src = Workbooks.Open("C:\Users\mys710048\Documents\EXCEL MONITORING FILE.xlsx", True, True)
' GET THE TOTAL ROWS FROM THE SOURCE WORKBOOK.
Dim iTotalRows As Integer
iTotalRows = src.Worksheets("INFO JPN MOTOR").Range("A1:A" & Cells(Rows.Count, "A").End(xlUp).Row).Rows.Count
' COPY DATA FROM SOURCE (CLOSE WORKGROUP) TO THE DESTINATION WORKBOOK.
Dim iCnt As Integer ' COUNTER.
For iCnt = 1 To iTotalRows
Worksheets("Sheet1").Range("A1:W1" & iCnt).Formula = src.Worksheets("INFO JPN MOTOR").Range("A1:W1" & iCnt).Formula
Next iCnt
' CLOSE THE SOURCE FILE.
src.Close False ' FALSE - DON'T SAVE THE SOURCE FILE.
Set src = Nothing
ErrHandler:
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
Now I like to add a timer which will refresh the data every one minute. I placed the code in my Workbook_Open sub:
Private Sub Workbook_Open()
Call ReadDataFromCloseFile
Application.OnTime Now + TimeValue("00:01:00"), "ReadDataFromCloseFile" 'Included recently'
End Sub
However, when doing so I receive an error message 1 minute later saying "Cannot run the macro ...The macro may not be available in the workbook or all marcros may be disabled." Which is clearly not the case considering I got it running before I placed the timer. And yes I did save it as xlsm format. Any solutions to this mess?
Does it work without that in there?
Alan.