vba - 如何根据下拉框动态改变一个形状数据
问题描述
我有一个用户表单,当电缆形状掉到工作表上时运行:该表单询问用户电缆分类是主要的还是次要的,以及托盘类型是主要的还是次要的。例如,如果选择了主电缆和桥架,则电缆类型+桥架形状数据将更改为仅包含主电缆和桥架的下拉列表。
Public shp3 As Shape
Private Sub CommandButton1_Click()
Dim CableClass As String
Dim TrayClass As String
Dim pg2 As Page
CableClass = ComboBox1.Value
TrayClass = ComboBox2.Value
Set shp3 = ActivePage.Shapes.ItemFromID(cID)
If CableClass = "Primary" Then
shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable
2;Cable 3;Cable 4"""
ElseIf CableClass = "Secondary" Then
shp3.Cells("Prop.Row_CableClass.Value").FormulaU = """Secondary"""
shp3.Cells("Prop.Row_CableType.Format").FormulaU = """Cable 1;Cable
2;Cable 3;Cable 4"""
End If
If TrayClass = "Primary" Then
shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Primary"""
shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray
1;cable tray 2;cable tray 3;cable tray 4"""
ElseIf TrayClass = "Secondary" Then
shp3.Cells("Prop.Row_TrayClass.Value").FormulaU = """Secondary"""
shp3.Cells("Prop.Row_TrayType.Format").FormulaU = """cable tray
1;cable tray 2;cable tray 3;cable tray 4"""
End If
Unload Me
End Sub
从形状数据中选择特定类型的电缆或托盘后,我希望成本会根据所选内容自动更改。换句话说,我希望根据从下拉框中选择的电缆类型动态更改一个形状数据(成本)。
解决方案
不是一个完整的答案,但对于评论来说太长/太复杂了:
在您的用户表单代码后面:
Private Sub CableClass_Change()
SetCableClassValues CableClass, shape
End Sub
Private Sub TrayClass_Change()
SetTrayClassValues TrayClass, shape
End Sub
在单独的标准模块中:
Public Sub SetCableClassValues (ByVal cableClass as ComboBox, ByVal theShape as Visio.Shape)
theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
theShape.... 'set the appropriate cost value here
End Sub
Public Sub SetTrayClassValues (ByVal trayClass as ComboBox, ByVal theShape as Visio.Shape)
theShape.Cells("Prop.Row_CableClass.Value").FormulaU = """Primary"""
theShape.... 'set the appropriate cost value here
End Sub
请注意,这都是“空气编码”,因此它不会完全按照所写的那样工作。但是,一旦您进入SetCableClassValues
例程,您就可以访问cableClass
组合框中的所有内容,就像您直接在代码隐藏中一样。您还可以访问- 您在现有代码中theShape
拥有的任何一个,您将作为参数传入。shp3
shape
如果您需要这两种信息来确定成本,那么您将有 1 个例程将组合框和形状作为参数,确保两者都选择了有效值,然后进行所有更新。
我对 Visio 对象模型一点也不熟悉,所以你必须弄清楚如何设置成本,但看起来你已经有足够的理解来处理这部分了。
推荐阅读
- python - 比较熊猫中两个数据框中的两列,如果它们相似,则获取另一列的值
- c# - 从类 C# 访问 app.config 中的变量
- android - 如何从 Android 中的 MainActivity 访问 onBindViewHolder 项值
- sql - SQL 蜂巢 | 表中的重复行
- angularjs - 如何通过 selenium webdriver 点击 Angular 元素?
- snowflake-cloud-data-platform - 如何在雪花UDF中调用mysql函数
- javascript - 笑话 - mockReturnValue : Promise
- python - 验证 POST 请求(Vue + DRF)
- android - 当我重新打开我的位置时,最近的车站没有显示
- machine-learning - 两个几乎完全相似的 Pytorch 神经网络实现,但精度始终不同