根据Excel表中的值在Visio中选择形状

问题描述 投票:0回答:1

我在Excel表格中有Visio形状ID的列表。当我在Excel中单击形状ID时,我希望Visio(同时打开)选择具有该ID的形状。

我已经改写了其他人的一些代码,这些人打开了Excel并允许从Visio进行修改,但是现在它朝着另一个方向发展。因此,这是第一个问题...也许将Visio称为对象与Excel有点不同。

代码没有引发任何错误,只是没有选择形状。

第二种可能性是我在Visio中选择的语法错误。

Public Sub GetVisio(shapeID)
    Dim MyVSO As Object    ' Variable to hold reference
                                ' to Microsoft Visio.
    Dim VisioWasNotRunning As Boolean    ' Flag for final release.

' Test to see if there is a copy of Microsoft Visio already running.
    On Error Resume Next    ' Defer error trapping.
' Getobject function called without the first argument returns a
' reference to an instance of the application. If the application isn't
' running, an error occurs.
    Set MyVSO = GetObject(, "Visio.Application")
    If Err.Number <> 0 Then VisioWasNotRunning = True
    Err.Clear    ' Clear Err object in case error occurred.

' Check for Microsoft Visio. If Microsoft Visio is running,
' enter it into the Running Object table.
    DetectVisio

' Set the object variable to reference the file you want to see.
    Set MyVSO = GetObject("I:\XL-Projekte\0PMO-Projekte\PMO.0023 - LN+\01 PMO\07_Prozess\LNplus_Sollprozess_PMO.vsd")

' Show Microsoft Visio through its Application property. Then
' show the actual window containing the file using the Windows
' collection of the MyVSO object reference.
    MyVSO.Application.Visible = True
    MyVSO.Parent.Windows(1).Visible = True
    ' Do manipulations of your file here.

    If shapeID > 0 Then

        intShapeID = CInt(shapeID)
        Debug.Print intShapeID
        MyVSO.ActiveWindow.Select Application.ActiveWindow.Page.Shapes.ItemFromID(intShapeID), visSelect

    End If

' If this copy of Microsoft Visio was not running when you
' started, close it using the Application property's Quit method.
' Note that when you try to quit Microsoft Visio, the
' title bar blinks and a message is displayed asking if you
' want to save any loaded files.
    If VisioWasNotRunning = True Then
        MyVSO.Application.Quit
    End If

    Set MyVSO = Nothing    ' Release reference to the
                                ' application and sheet.
End Sub
excel vba visio
1个回答
0
投票

所以今天我打开了Visio和Excel,每当我尝试从Excel运行代码时,Visio都会要求激活宏。因此,我将Visio文件保存为启用了宏的图形,现在我的代码可以正常工作了!奇怪的是,前几天Visio并没有询问启用宏,而是根本没有响应。

© www.soinside.com 2019 - 2024. All rights reserved.