The error is triggered when the third worksheet is referenced. If I coment out the third Gosub the macro works. When I added the second sheet I found a way to add a worksheet but I can't remember it or find it now . The way included selecting something in the project window and typing a Cntl and another key. This brought up a window that allowed me to add the worksheet.
I had to shorten my code to include it here:
Sub PokeCardNumbers()
Dim channelNumber
Dim sheetNumber
Dim rangeToPoke
channelNumber = Application.DDEInitiate("MBENET", "PLC1")
sheetNumber = 1
GoSub WriteData
Application.DDETerminate channelNumber
channelNumber = Application.DDEInitiate("MBENET", "PLC2")
sheetNumber = 3
GoSub WriteData
Application.DDETerminate channelNumber
channelNumber = Application.DDEInitiate("MBENET", "PLC3")
sheetNumber = 5
GoSub WriteData
Application.DDETerminate channelNumber
Exit Sub
WriteData:
Set rangeToPoke = ThisWorkbook.Worksheets(sheetNumber).Range("E3")
If rangeToPoke.Value <> 65535 Then
Application.DDEPoke channelNumber, "40001", rangeToPoke
rangeToPoke.Value = 65535
End If
Return
End Sub
Bookmarks