Excel VBA: RsLinx DDE example

'Initialize DDE
channelNumber = Application.DDEInitiate("RSLinx", "SomeTopicName")

'Read from PLC5
readValue = DDERequest(channelNumber, "N20:1")
'Read from ControlLogix
readValue = DDERequest(channelNumber, "ControlLogixTag[1]")

'Write to PLC
Set rangeToPoke = Worksheet("Sheet1").Range("A1")

'Write to PLC5
Application.DDEPoke channelNumber, "N20:2", rangeToPoke
'Write to ControlLogix
Application.DDEPoke channelNumber, "ControlLogixTag[1]", rangeToPoke

'End DDE
Application.DDETerminate channelNumber

Excel VBA: Excel Version

Use Application.Version property to find out the version of Microsoft Excel. Useful to check for Microsoft Excel version to test the number of rows.

Example Syntax:

MsgBox (Application.Version)

Version Number:

  • 15.0 – 2013
  • 14.0 – 2010
  • 12.0 – 2007
  • 11.0 – 2003

Excel VBA: Speed up macro execution

Speed up macro execution by turning off screen updating/flicker.

'Turn Off Screen Updating
Application.ScreenUpdating = False
'Optional: Refresh/Update screen manually when needed
Application.ScreenRefresh

'Your Code

'Turn On Screen Updating
Application.ScreenUpdating = True

Excel VBA: Check for Comments

'If Comment does not exist
 If Range("B4").Comment Is Nothing Then
 Range("B4").Value = "Does not exist."
 End If

 'If Comment exist
 If Not Range("C4").Comment Is Nothing Then
 Range("C4").Value = Range("C4").Comment.Text
 End If