vbavisio

Select Case with Like


I want to move objects based on a string.

enter image description here

I found https://www.youtube.com/watch?v=DAS0guHvJZk&ab_channel=VigilIT-video

My code looks like this:

Sub finalsort()
Dim DiagramServices As Integer
DiagramServices = ActiveDocument.DiagramServicesEnabled
Dim ViPage As Page
Set ViPage = ActiveDocument.Pages("SLD")
Dim vShp As Visio.Shape
Dim subShp As Visio.Shape
Dim Shpname As String

Dim sel As Visio.Selection

For Each vShp In ViPage.Shapes
    For Each subShp In vShp.Shapes
        Select Case subShp
            Case subShp.Characters.Text Like "*AA**"
                ActiveWindow.Select vShp, visSubSelect
                vShp.Cells("PinY").Formula = "80mm"
                vShp.Cells("PinX").Formula = "180mm"
        End Select
    Next subShp
Next vShp

End Sub

No error, but also no action.


Solution

  • Please read about Select Case Statement syntax!
    I found this article VBA select case like: operator, string, statement, please look at chapter How to use the True expression.
    For your purpose try this way

    Select Case True
    Case subShp.Characters.Text Like "*AA**"
    ActiveWindow.Select vShp, visSubSelect
    vShp.Cells("PinY").Formula = "80mm"
    vShp.Cells("PinX").Formula = "180mm"
    ' iterate other conditions
    End Select