Search code examples
excelvbams-accessms-project

how to run a macro on another application using vba


i have an access 2007 database and i need to create a button on a form that when i click on it it will run a macro on another office application like visio and ms project

the following link show how to make it for other applications like word and excel but it doesnt show how to make it in case of visio or ms project applications

https://support.microsoft.com/en-us/kb/177760

Sub Procedure to Run an Existing Microsoft Excel Macro

The following Sub procedure assumes that the workbook ExcelFile.xls contains a macro called "TestMacro."

 Sub XLTest()
  Dim XL as Object

  Set XL = CreateObject("Excel.Application")

  XL.Workbooks.Open "C:\My Documents\ExcelFile.xls"

  ' If there is more than one macro called TestMacro,
  ' the module name would be required as in
  '
  ' XL.Run "Module1.TestMacro"
  '
  ' to differentiate which routine is being called.
  '
  XL.Run "TestMacro"

 End Sub

Sub Procedure to Run an Existing Microsoft PowerPoint Macro

The following Sub procedure assumes that the presentation PPTAutomation.ppt contains a macro called "AutomationTest."

 Sub PPTTest()
  Dim PPT as Object

  Set PPT = CreateObject("PowerPoint.Application")

  PPT.Presentations.Open "C:\My Documents\PPTAutomation.ppt", , ,False

  ' Note that the file name and the module
  ' name are required to path the macro correctly.
  PPT.Run "PPTAutomation.ppt!Module1.AutomationTest"

 End Sub

Sub Procedure to Run an Existing Microsoft Word Macro

The following Sub procedure assumes that the document WordDoc.Doc contains a macro called "WordMacro."

  Sub WDTest()
  Dim WD as Object

  Set WD = CreateObject("Word.Application")

  WD.Documents.Open "C:\My Documents\WordDoc.Doc"

  ' Note that the project name and module name are required to
  ' path the macro correctly.
  WD.Run "Project.Module1.WordMacro"

 End Sub

any suggestions please ?


Solution

  • Visio:

    Sub VISTest()
        Dim VIS as Object
    
        Set VIS= CreateObject("Visio.Application")
    
        VIS.Documents.Open "PATH"
    
        ' Note that the project name and module name are required to
        ' path the macro correctly.
        VIS.Run "MARCRONAME"
    
    End Sub
    

    Project:

    I could not test project, not having it, but look here https://msdn.microsoft.com/en-us/library/bb223292%28v=office.12%29.aspx saying

    Dim pj As Object
    
    Set pj = CreateObject("MSProject.Project")
    pj.Application.FileOpen "My Project.mpp"
    

    Be careful to enable macros in the trust center of the Office-Applications