【发布时间】:2020-02-07 16:32:26
【问题描述】:
我有 4 个形状,在一个组中,“客户、供应商、潜在客户、嫌疑人”。我希望能够选择一种形状来改变风格,但一次只允许其中一种成为那种风格。所以如果CustomerStyle是msoShapeStyle31,那么我希望其他3个都是msoShapeStyle32;但如果用户单击其他 3 个按钮之一,则该按钮应更改为 msoShapeStyle31,其余 3 个按钮将转换为 msoShapeStyle32。我希望这是有道理的。
RelationshipButtons 是组,我计划根据其中一个形状是 msoShapeStyle31 输出一个单元格值。
这就是我所拥有的,但这是不对的,因为他们中的几个人同时转向 msoShapeStyle31,而它一次应该只有一个。有什么帮助吗?
Sub Button_Colors()
With Sheet1
Dim CustomerButton As Shape, VendorButton As Shape, ProspectButton As Shape, SuspectButton As Shape, RelationshipButtons As Shape
Set CustomerButton = .Shapes("CustomerButton")
Set VendorButton = .Shapes("VendorButton")
Set ProspectButton = .Shapes("ProspectButton")
Set SuspectButton = .Shapes("SuspectButton")
Set RelationshipButtons = .Shapes("RelationshipButtons")
Dim CustomerStyle As Integer, VendorStyle As Integer, ProspectStyle As Integer, SuspectStyle As Integer
CustomerStyle = CustomerButton.ShapeStyle
VendorStyle = VendorButton.ShapeStyle
ProspectStyle = ProspectButton.ShapeStyle
SuspectStyle = SuspectButton.ShapeStyle
With RelationshipButtons
If CustomerStyle = 31 Then
CustomerStyle = msoShapeStylePreset32
VendorStyle = msoShapeStylePreset31
ProspectStyle = msoShapeStylePreset31
SuspectStyle = msoShapeStylePreset31
ElseIf VendorStyle = 31 Then
CustomerStyle = msoShapeStylePreset31
VendorStyle = msoShapeStylePreset32
ProspectStyle = msoShapeStylePreset31
SuspectStyle = msoShapeStylePreset31
ElseIf ProspectStyle = 31 Then
CustomerStyle = msoShapeStylePreset31
VendorStyle = msoShapeStylePreset31
ProspectStyle = msoShapeStylePreset32
SuspectStyle = msoShapeStylePreset31
ElseIf SuspectStyle = 31 Then
CustomerStyle = msoShapeStylePreset31
VendorStyle = msoShapeStylePreset31
ProspectStyle = msoShapeStylePreset31
SuspectStyle = msoShapeStylePreset32
End If
End With
CustomerButton.ShapeStyle = CustomerStyle
VendorButton.ShapeStyle = VendorStyle
ProspectButton.ShapeStyle = ProspectStyle
SuspectButton.ShapeStyle = SuspectStyle
End With
End Sub
【问题讨论】:
-
您想用
RelationshipButtons形状做什么?With ... End With没有任何意义,因为没有涉及“RelationshipButtons”方面的任何内容......你的按钮是什么类型的控件? ActiveX 控件,还是表单控件?我认为你应该使用他们的Click事件。我无法理解该代码是如何工作的,即使不是完美的。你不是说只有在按下其中一个按钮时才能更改样式?如果是,那么在您的代码中的哪个位置按下了按钮?如果不是,您如何想象您的代码使用了Click事件? -
你的形状真的是按钮,还是普通的矩形?你是如何创造它们的?抱歉,您知道 VBA 中的按钮是什么吗?
-
对不起,我应该更具体一些。它们是形状,我将其用作按钮。我意识到有区别。
-
RelationshipButtons 形状是一组形状;没有必要吗?
-
需要什么?您是否至少为这些伪按钮分配了宏?
标签: vba button grouping shapes