Article ID: 151269
Article Last Modified on 10/11/2006
On Error Resume Next ' Set up error handler.
Dim Chan, SheetName, I, TopicList ' Declare variables.
Chan = DDEInitiate("Excel", "System") ' Establish spreadsheet link.
If Err Then ' If error occurs, spreadsheet
Err = 0 ' isn't running. Reset error
I = Shell("Excel", 1) ' and start spreadsheet.
If Err Then Exit Sub ' If another error, exit.
Chan = DDEInitiate("Excel", "System") ' Establish spreadsheet link.
End If
DDEExecute Chan, "[New(1)]" ' Create new worksheet.
TopicList = DDERequest(Chan, "Selection") ' Get topic list, worksheet
' name.
SheetName = Left(TopicList, InStr(1, TopicList, "!") - 1)
DDETerminate Chan ' Terminate DDE link.
Chan = DDEInitiate("Excel", SheetName) ' Establish link with new
' worksheet.
For I = 1 To 10 ' Put some values into
DDEPoke Chan, "R1C" & I, I ' first row.
Next I
DDEExecute Chan, "[Select(""R1C1:R1C10"")][New(2,2)]" ' Make chart.
DDETerminateAll ' Terminate all links.
For additional information, please see the following article in the
Microsoft Knowledge Base:
139881 XL: Sample Code Demonstrating DDEPoke and POKE()
On Error Resume Next ' Set up error handler.
Dim chan, SheetName, I, TopicList, rangeToPoke ' Declare variables.
chan = DDEInitiate("Excel", "System") ' Establish spreadsheet link.
If Err Then ' If error occurs, spreadsheet
Err = 0 ' isn't running. Reset error
I = Shell("Excel", 1) ' and start spreadsheet.
If Err Then Exit Sub ' If another error, exit.
chan = DDEInitiate("Excel", "System") ' Establish spreadsheet link.
End If
DDEExecute chan, "[New(1)]" ' Create new worksheet.
TopicList = DDERequest(chan, "Selection") ' Get topic list, worksheet
' name.
SheetName = Left(TopicList, InStr(1, TopicList, "!") - 1)
DDETerminate chan ' Terminate DDE link.
chan = DDEInitiate("Excel", SheetName) ' Establish link with new
' worksheet.
For I = 1 To 10
Set rangeToPoke = ThisWorkbook.Worksheets(1).Range("a1")
rangeToPoke.Value = I ' Put some values into
DDEPoke chan, "R1C" & I, rangeToPoke ' first row.
Next I
DDEExecute chan, "[Select(""R1C1:R1C10"")][New(2,2)]" ' Make chart.
DDETerminate chan ' Terminate link.
The following changes were made to the original example:
Dim chan, SheetName, I, TopicList
to:
Dim chan, SheetName, I, TopicList, rangeToPoke
adding rangeToPoke.
For I = 1 To 10
DDEPoke Chan, "R1C" & I, I
Next I
to:
For I = 1 To 10
Set rangeToPoke = ThisWorkbook.Worksheets(1).Range("a1")
rangeToPoke.Value = I
DDEPoke chan, "R1C" & I, rangeToPoke
Next I
DDETerminateAll
to:
DDETerminate chanAdditional query words: 7.00a XL7
Keywords: kbprogramming KB151269