在 VISIO VBA 中设置图像透明度

发布于 2025-01-13 03:47:14 字数 761 浏览 0 评论 0原文

我只是想就我遇到的问题请求帮助。我不知道我是否在做以下正确的事情,所以希望得到您最友善的指导。

我在 MS visio 中设置了一个 activeX 切换按钮,我试图用它来控制我放置在同一页面中的图像。

我想做的是,当按下切换按钮时,图像透明度将为 100,未按下时,图像透明度将为 0。

下面是我的代码,但由于某种原因,它不会对图像执行任何操作。我已经从形状表中检查了图像的名称。

预先感谢您对此提供的任何帮助和指导。

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

小情绪 2025-01-20 03:47:14

针对上面的问题,我找到了一种让图像不可见的方法。操作形状表不起作用,因此作为解决方法,我只是为图像添加了一个图层,并让切换框控制图层的可见性。下面是我使用的代码。

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

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
別甾虛僞 2025-01-20 03:47:14

feddyo013,你好!

您必须在公式中添加百分号 (%)。

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

输入图像此处描述

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文