I just upgraded from excel 2010 to 2016 and now I am getting a debug error when I start the macro at the line 'Workbooks("Live Trade Monitor - IB.xlsm").Worksheets("Live Trades").Select' only if my cursor is selecting a cell in a separate excel workbook that I have open. If my cursor is selecting a cell in the active workbook in which this macro runs then the code runs correctly. If someone can help me correct this error I would appreciate it. Thanks
The error that I am receiving is
Run time error '1004'
Select method of worksheet class failed
Option Explicit
Dim iCount As Integer, iNumber As Integer, rStart As Range
Sub CopyLiveTradeData()
Dim UserInput As Integer
UserInput = MsgBox(Title:="Confirm Continue", _
Prompt:="Are you sure you want to start the PnL recorder?", _
Buttons:=vbYesNo)
If UserInput = vbNo Then Exit Sub
'If user clicked yes, any code below this point will run
'For example:
Application.OnTime TimeValue(ThisWorkbook.Sheets("Live Trades").Range("X57").Value), "StartOnTime"
End Sub
Private Sub StartOnTime()
iCount = 0
iNumber = 20000
Workbooks("Live Trade Monitor - IB.xlsm").Worksheets("Live Trades").Select
Call OnTimeMacro
End Sub
Private Sub OnTimeMacro()
If Time < TimeSerial(15, 59, 0) Then
iCount = iCount + 1
Application.OnTime Now + TimeValue("00:00:30"), "RunEveryXMinute"
Else
Workbooks("Live Trade Monitor - IB.xlsm").Worksheets("Live Trades").Select
End If
End Sub
Bookmarks