【问题标题】:Run Visio Macro from Excel and pass parameters从 Excel 运行 Visio 宏并传递参数
【发布时间】:2021-05-21 21:26:37
【问题描述】:

我编写了以下 Excel 宏来调用打开的 Visio 文件中的另一个宏:

Private Sub visio_change_shape(Index_value As Integer)

Dim AppVisio As Object
Dim VisioSystems As Object

Set AppVisio = GetObject(, "Visio.Application")
Set VisioSystems = AppVisio.Documents(1)

VisioSystems.ExecuteLine ("Select_Shape_excel")
End Sub

这个宏工作正常。但是,当我想通过同一个宏传递一个整数时,我得到一个异常错误:

Private Sub visio_change_shape(Index_value As Integer)

Dim AppVisio As Object
Dim VisioSystems As Object

Set AppVisio = GetObject(, "Visio.Application")
Set VisioSystems = AppVisio.Documents(1)

VisioSystems.ExecuteLine ("Select_Shape_excel Index_value")  '<--Error occurs here
End Sub

基于Microsoft documentation,这应该是正确的。任何想法为什么我会收到错误?

【问题讨论】:

  • 首先,将 () 放在要传递给 ExecuteLine 的参数周围(我知道这是文档时代要做的事情,但这不是 MS 文档第一次出错) .其次你要传递Index_value的值,所以使用VisioSystems.ExecuteLine "Select_Shape_excel " &amp; Index_value
  • @chrisneilsen 感谢您的反馈,但同样的错误仍然发生。
  • @VBAPete 我想你想使用Document 而不是Documents。只有Document 对象有ExcecuteLine 方法:docs.microsoft.com/en-us/office/vba/api/…

标签: excel vba visio


【解决方案1】:

要调用您可以使用的过程:

例如哔 17

调用(参数)

例如呼叫哔(17)

完整的描述见:

Microsoft VBA - Calling Sub and Function procedures

【讨论】:

  • 感谢您的链接。在这个例子中会是什么样子? Call VisioSystems.SelectLayers.Select_Shape_excel(Index_value)?
  • 仅供参考,SelectLayers 是宏所在的 visio 模块的名称。
  • 当您在编辑器中输入文本时,它应该为您提供各种选项。
  • 选项太多,无法找出正确答案...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-03-30
  • 2011-12-18
  • 2020-04-23
  • 2015-11-13
  • 2015-07-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多