Knowledge Base

Running a Microsoft Project Macro from Microsoft Excel

Article ID: 133710

Article Last Modified on 10/11/2006


APPLIES TO


This article was previously published under Q133710

SUMMARY

This article contains an example to demonstrate how Microsoft Excel can run a Microsoft Project macro using DDE (dynamic data exchange) and Visual Basic for Applications code.

MORE INFORMATION

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. This example starts Microsoft Project and then runs a macro from the global macros.
  1. In Microsoft Excel, create a new workbook.
  2. In Microsoft Excel 97, click the Tools menu, point to Macro, and click Visual Basic Editor. Then, click Module on the Insert menu.

    In earlier versions, on the Insert menu, click Macro, and then click Module.
  3. Type the following information in the module sheet (you may need to alter the macro to specify the appropriate locations for the files on your computer):
       Sub Run_Project_Macro()
    
           'Opens Microsoft Project
           Shell("c:\project\winproj.exe")
    
           'Initiates a DDE channel to Microsoft Project
           Chan = DDEInitiate("WINPROJ", "system")
    
           'Activates Microsoft Project
           Application.ActivateMicrosoftApp xlMicrosoftProject
    
           'Runs the Project global macro "AdjustDates"
           Application.DDEExecute Chan, "AdjustDates"
    
           'Terminates the DDE channel
           Application.DDETerminate Chan
    
       End Sub
    					
  4. To run the macro, on the Tools menu, click Macro. Select the appropriate macro name and then click Run.

Additional query words: 5.00c 8.00 97 XL97 XL

Keywords: kbhowto kbinterop kbprogramming kbdtacode KB133710