VBA宏关闭DDE链接

时间:2014-12-24 18:20:31

标签: vba vbscript

我在Excel电子表格中遇到DDE链接问题。它冻结了。我认为这可能是由旧的DDE链接引起的,我有这个脚本我试图关闭所有DDE链接。每当我运行它时,我会得到,

线:2 查尔:24 错误:预期的结束语句 代码:800A0401 来源:Microsoft VBScript编译错误

以下是代码:

Sub KillDDE()
  Dim i, ChannelNumber As Integer
  For i = 1 To 1000
    Application.DDETerminate (i) ' Closes all DDE links whose channels might be open
    Next i
  ChannelNumber = Application.DDEInitiate("prortDDE", "DAX") 'initiates a new channel for a DDE link
  Range("A2").Value = Application.DDERequest(ChannelNumber, "Last")

End Sub

1 个答案:

答案 0 :(得分:0)

应该有所帮助的两件事:

  1. 使用Application.DDETerminateAll方法found HERE
  2. According to MSDN Application.DDEInitiate返回Long所以Dim ChannelNumber As Long