Visio Guy

Visio => ShapeSheet & Smart Shapes => Topic started by: big-igor on July 02, 2010, 07:18:06 AM

Title: Inserting Formulas in ShapeSheetCells via VBA
Post by: big-igor on July 02, 2010, 07:18:06 AM
Hey guys,
I'm kind of desperate by now, I have a VBA form with 2 buttons on it. When clicking on one of them, i want Visio to insert a specific formula (that contains a reference to the selected shape group) into some cells of shape#123's ShapeSheet.
Problem: I click on Button1 --> The formula is inserted.
I click on Button2 --> The new formula should replace the old one, but nothing happens.

Could somebody help me out? Thanks in advance!!

Code: [Select]
Private Sub CommandButton1_Click()
        Dim xshape As Visio.Shape
        Dim groupid As Integer
        groupid = Application.ActiveWindow.Selection.PrimaryItem.id
        Set xshape = Application.ActiveWindow.Page.Shapes.ItemFromID(123)
        xshape.Cells("Geometry1.NoShow").Formula = "Sheet." & groupid & "!User.extHide"
        xshape.Cells("HideText").Formula = "Sheet." & groupid & "!User.extHide"
        xshape.Cells("Transparency").Formula = "Sheet." & groupid & "!User.extHide"
End Sub

Private Sub CommandButton2_Click()
        Dim xshape As Visio.Shape
        Dim groupid As Integer
        groupid = Application.ActiveWindow.Selection.PrimaryItem.id
        Set xshape = Application.ActiveWindow.Page.Shapes.ItemFromID(123)
        xshape.Cells("Geometry1.NoShow").Formula = "Sheet." & groupid & "!User.fsHide"
        xshape.Cells("HideText").Formula = "Sheet." & groupid & "!User.fsHide"
        xshape.Cells("Transparency").Formula = "Sheet." & groupid & "!User.fsHide"

End Sub
Title: Re: Inserting Formulas in ShapeSheetCells via VBA
Post by: aledlund on July 03, 2010, 06:56:56 AM
I'd start with the fact that both buttons rely upon something being selected in the window, but you never test to see if a selection has really happened. I'd then wrap the code in a "on error goto " routine so that you can catch any errors that may be happening (right now your code can fail silently and you may get lost). Without a drawing with your custom shapes it's pretty much up in the air.
al