Home > Mobile >  Setting Image Transparency in VISIO VBA
Setting Image Transparency in VISIO VBA

Time:03-16

I would just like to request assistance in relation to a concern that I experienced. I do not know if I am doing the below right so hoping for your kindest guidance.

I have setup an activeX toggle button in MS visio which I am trying to use to control an image that I have placed in the same page.

What I am trying to do is when the togglebutton is pressed the image transparency will be 100 and when it is not pressed it will be 0.

Below is my code, but for some reason it is not doing anything to the image. I have checked from shapesheet the name of the image.

Thank you in advance for any help and guidance on this.

Private Sub ToggleButton1_Click()
Dim shp As Visio.Shape
If Me.ToggleButton1.Value = True Then
    Set shp = Application.ActiveDocument.Pages("Page-1").Shapes("Sheet.1")
    shp.CellsSRC(visSectionObject, visRowImage, visImageTransparency).FormulaForceU = "100"
    
ElseIf Me.ToggleButton1.Value = False Then
    Set shp = Application.ActiveDocument.Pages("Page-1").Shapes("Sheet.1")
    shp.CellsSRC(visSectionObject, visRowImage, visImageTransparency).FormulaForceU = "0"
End If

End Sub

CodePudding user response:

In relation to the above question, I found a way to make the image invisible. Manipulating the shapesheet did not work so as a work around I just added a layer for the image and have the toggle box control the layer visibility instead. Below is the code I used.

Private Sub ToggleButton1_Click()
Dim layr As Visio.Layer
Set layr = Visio.ActivePage.Layers.Item("check1")
If Me.ToggleButton1.Value = True Then
    layr.CellsC(visLayerVisible) = 1
ElseIf Me.ToggleButton1.Value = False Then
    layr.CellsC(visLayerVisible) = 0
End If
End Sub

CodePudding user response:

feddyo013, hi there !

You must add percent sign (%) in your formulas.

Private Sub ToggleButton1_Click()
Dim shp As Visio.Shape
If Me.ToggleButton1.Value = True Then
    Set shp = Application.ActiveDocument.Pages("Page-1").Shapes("Sheet.1")
    shp.CellsSRC(visSectionObject, visRowImage, visImageTransparency).FormulaForceU = "100%"
    
ElseIf Me.ToggleButton1.Value = False Then
    Set shp = Application.ActiveDocument.Pages("Page-1").Shapes("Sheet.1")
    shp.CellsSRC(visSectionObject, visRowImage, visImageTransparency).FormulaForceU = "0%"
End If

End Sub

enter image description here

  • Related