Article ID: 128619
Article Last Modified on 1/19/2007
'This macro is in a Microsoft Project module in GLOBAL.MPT.
'It is called from the Microsoft Excel macro below.
Sub ProjectMacro1(sName As String, longMinutes As Long)
'declare variables
Dim T As Object
'create a new task and set the name based on passed parameter "sName"
Set T = ActiveProject.Tasks.Add (Name:=sName)
'set new task's duration equal to passed parameter "longMinutes"
T.Duration = longMinutes
End Sub
'This macro is in a Microsoft Excel module; when you run it,
'it calls the above Microsoft Project macro procedure.
Sub ExcelMacro1()
'declare variables
Dim channel As Integer, command As String
'establish a DDE channel to Microsoft Project's system topic
channel = DDEInitiate("winproj","system")
'create a command string
'double quotes are used to quote an item within a quoted string
command = "ProjectMacro1 ""Plumbing"", 48000"
'send command string to Microsoft Project
DDEExecute channel, command
'terminate DDE channel to Microsoft Project
DDETerminate channel
End Sub
The DDE command string that Microsoft Project sees is:
ProjectMacro1 "Plumbing", 48000
'This macro is in an Excel module; when run,
'it calls the above Microsoft Project macro.
'The worksheet containing this data must be
'active when the macro is run.
Sub ExcelMacro2()
'declare variables
Dim channel As Integer, command As String
Dim stringX As String, longY As Long
'store values in spreadsheet cells into variables
stringX = Range("A1")
longY = Range("B1")
channel = DDEInitiate("winproj","system")
'Chr(34) is the quote character. It is used to concatenate
'quotes around the stringX variable in the DDE command string.
command = "ProjectMacro1 " & Chr(34) & stringX & Chr(34) & _
", " & longY
'The quote character could have been incorporated directly,
'without the Chr function, as follows:
'command = "ProjectMacro1 """ & stringX & """, " & longY
DDEExecute channel, command
DDETerminate channel
End Sub
The DDE command string that Microsoft Project sees is:
ProjectMacro1 "Plumbing", 48000
Additional query words: parameter function procedure value send
Keywords: kbcode kbhowto kbprogramming KB128619