Inserting Formulas in ShapeSheetCells via VBA

Started by big-igor, July 02, 2010, 12:18:06 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

big-igor

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!!


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

aledlund

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