Visual Basic Examples Using DDE with Program Manager (123443)



The information in this article applies to:

  • Microsoft Excel for Windows 5.0c

This article was previously published under Q123443
This article also applies to:
  • Microsoft Excel for Windows 5.0|5.0

SUMMARY

The following information includes Visual Basic procedures that you can use in Microsoft Excel to return information from Program Manager and to perform actions on Program Manager groups and items using Dynamic Data Exchange (DDE) commands.

These examples demonstrate how to do the following:

  • Create a New Group
  • Delete an Existing Group
  • Add a New Item
  • Maximize, Minimize or Restore a Group Window
  • Return a List of Groups

MORE INFORMATION

The application name for Program Manager is "ProgMan." The topic available in the Program Manager application is also "ProgMan." The following is a list of commands available in the ProgMan topic that you can use in a DDE conversation with Program Manager:

CreateGroup(GroupName,GroupPath)

Creates a new group at Program Manager or activates the window of an existing group.

DeleteGroup(GroupName)

Deletes an existing program group.

AddItem(CmdLine,Name,IconPath,

Creates a new program item (icon) in the IconIndex,xPos,yPos, active group. DefDir,HotKey,,fMinimize)

ShowGroup(GroupName,ShowCommand)

Maximizes, minimizes, or restores a group window.

You can also request the "progman" item to return a list of your Program Manager groups.

EXAMPLES

Create New Group

The following example creates a group called "Excel Files" or activates an existing group named "Excel Files" in Program Manager.
   Sub CreateGroup()
      Dim Chan As Integer
      Chan = DDEInitiate("Progman", "progman")
      DDEExecute Chan, "[CreateGroup(Excel Files)]"

      ' Terminate channel
      DDETerminate Chan
   End Sub
				

Delete Existing Group

The following example deletes the group "Excel Files." Note that the group is deleted even if it contains items.
     Sub DeleteGroup()

      Dim Chan As Integer
      Chan = DDEInitiate("Progman", "progman")
      DDEExecute Chan, "[DeleteGroup(Excel Files)]"

      ' Terminate channel
      DDETerminate Chan
   End Sub
				

Add New Item

The following example prompts you to enter a path to the item (c:\excel\excel.exe) and a name for the item (Excel), and then adds the item to the active group:
   Sub AddItem()
      Dim qt As String
      Dim Chan As Integer
      Dim path As String, item As String

      ' Set qt equal to quotation mark character
      qt = Chr(34)

      Chan = DDEInitiate("Progman", "progman")
      path = InputBox("Enter path for item")
      item = InputBox("Enter name for item")

      DDEExecute Chan, _
         "[AddItem(" & qt & path & qt & "," & qt & item & qt & ")]"

      ' Terminate channel
      DDETerminate Chan
   End Sub
				

Maximize, Minimize or Restore Group Window

   Sub GroupWindow()
      Dim Chan As Integer
      Chan = DDEInitiate("Progman", "progman")
      ' Maximize Excel Files group
      DDEExecute Chan, "[ShowGroup(Excel Files,3)]"
      ' Minimize Excel Files group
      DDEExecute Chan, "[ShowGroup(Excel Files,2)]"
      ' Restore Excel Files group
      DDEExecute Chan, "[ShowGroup(Excel Files,1)]"

      ' Terminate channel
      DDETerminate Chan
   End Sub
				

Return List of Groups

The following example returns a list of your Program Manager groups to Sheet1 in the active workbook:
Dim Chan as Integer
Dim listing as Variant
Dim i as Integer

   Sub ListGroups
      Chan = DDEInitiate("Progman","Progman")
      listing = DDERequest(Chan,"Progman")

      ' Terminate channel
      DDETerminate Chan

      i=1
      While i <= UBound(listing)
         Sheets("sheet1").Cells(i,1).FormulaR1C1=listing(i,1)
         i=i+1
      Wend

   End Sub
				
Microsoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support professionals can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400.

For additional information, please see the following article(s) in the Microsoft Knowledge Base:

72907 Manipulating Program Manager Groups Using DDE Interface

REFERENCES

For more information about the DDEExecute Method, the DDEInitiate Method, or the DDETerminate Method, choose the Search button in the Visual Basic Reference and type:

DDE: channels


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbenv kbinterop kbProgramming KB123443