我正在使用一个函数来返回通过选项按钮选择的值
https://www.engram9.info/excel-2003-vba/a-useful-but-not-so-simple-dynamic-userform-example.html。
然而,它给出了一个错误“类型不匹配”,在不太远。为了简化问题,我已经将代码精简了一点,希望留下所有必要的东西来回答这个问题。
我还没能找到所需的信息。
Function GetOption(OpArray, Default, Title)
'https://www.engram9.info/excel-2003-vba/a-useful-but-not-so-
'simple-dynamic-userform-example.html
Dim TempForm As Object
Dim NewOptionButton As Msforms.OptionButton
Dim MaxWidth As Long
'Create the UserForm
Set TempForm = ThisWorkbook.VBProject.VBComponents.Add(3)
TempForm.Properties("Width") = 800
'Add the OptionButtons TopPos = 4
MaxWidth = 0
Set NewOptionButton = TempForm.Designer.Controls m
'Type mis-match here
End Function下面是调用sub:
Sub TestGetOption()
Dim Ops(1 To 5)
Dim UserOption
Ops(1) = "North"
Ops(2) = "South"
Ops(3) = "West"
Ops(4) = "East"
Ops(5) = "All Regions"
UserOption = GetOption(Ops, 5, "Select a region")
Debug.Print UserOption
MsgBox Ops(UserOption)
End Sub错误消息是“类型不匹配”
发布于 2019-09-15 12:57:30
在添加新的选项按钮时,需要使用Controls对象的Add方法,并且需要提供控件的ProgID ...
Set NewOptionButton = TempForm.Designer.Controls.Add("Forms.OptionButton.1")有关更多信息,请查看以下链接...
https://stackoverflow.com/questions/57940851
复制相似问题