简体   繁体   English

如何使用 vba 在另一个应用程序上运行宏

[英]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我有一个 2007 数据库,我需要在表单上创建一个按钮,当我点击它时,它将在另一个办公应用程序(如 visio 和 ms 项目)上运行宏

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以下链接显示了如何为 word 和 excel 等其他应用程序制作它,但它没有显示如何在 visio 或 ms 项目应用程序的情况下制作它

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

Sub Procedure to Run an Existing Microsoft Excel Macro运行现有 Microsoft Excel 宏的子过程

The following Sub procedure assumes that the workbook ExcelFile.xls contains a macro called "TestMacro."下面的 Sub 过程假定工作簿 ExcelFile.xls 包含一个名为“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运行现有 Microsoft PowerPoint 宏的子过程

The following Sub procedure assumes that the presentation PPTAutomation.ppt contains a macro called "AutomationTest."下面的 Sub 过程假定演示文稿 PPTAutomation.ppt 包含一个名为“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运行现有 Microsoft Word 宏的子过程

The following Sub procedure assumes that the document WordDoc.Doc contains a macro called "WordMacro."下面的 Sub 过程假定文档 WordDoc.Doc 包含一个名为“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 ?请问有什么建议吗?

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我无法测试项目,没有它,但看这里https://msdn.microsoft.com/en-us/library/bb223292%28v=office.12%29.aspx

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小心在 Office-Applications 的信任中心启用宏

I have created a rule in Outlook to run a script.我在 Outlook 中创建了一个规则来运行脚本。 Using the script, I'm opening an Excel file and running the Excel Macro.使用脚本,我打开一个 Excel 文件并运行 Excel 宏。 The Excel Macro runs, and by the results I get, I can see the files are opened, but NO Excesl session is visible. Excel 宏运行,根据我得到的结果,我可以看到文件已打开,但没有 Excel 会话可见。 How can I make the Excel session visible?如何使 Excel 会话可见? My code goes like this:我的代码是这样的:

Public Sub RunScript(Item As Outlook.MailItem)公共子运行脚本(项目为 Outlook.MailItem)

Dim Path As String
Dim XL As Object
Dim FileName As String

If Item.Subject = "I place here the subject" Then
   Path = "C:\Users\....\Documents\"
   FileName = "Filename.xlsm"
   Set XL = CreateObject("Excel.Application")
   XL.Workbooks.Open Path & FileName
   XL.Run "ExcelMacroName"
End If

End Sub结束子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM