如何将combobox 中的selecteditem 传递到字串?

jackhu 2007-07-10 11:56:09
Private Sub ComboBox2_Change(ByVal v2)
ActiveSheet.Shapes("ComboBox2").Select
Selection.ListFillRange = "G25:G35"

Dim instance2 As ComboBox
value2 = instance2.SelectedItem
instance2.SelectedItem = value2
v2 = value2.tostring
End Sub

不工作,谢谢先
...全文
242 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
jackhu 2007-07-11
  • 打赏
  • 举报
回复
I have already figured it out, thank you for browsing this!
jackhu 2007-07-10
  • 打赏
  • 举报
回复
//All codes are in the current sheet

Private Sub ComboBox1_Change()
'fill items into combobox1
ActiveSheet.Shapes("ComboBox1").Select
Selection.ListFillRange = "M28:M37"
'copy the one selected item from combobox into a static value
Dim value1 As Variant
Static v1 As String
value1 = Me.ComboBox1.Text
v1 = value1
End Sub

Private Sub ComboBox2_Change()
'fill items into combobox1
ActiveSheet.Shapes("ComboBox2").Select
Selection.ListFillRange = "O28:O37"
'copy the one selected item from combobox into a static value
Dim value2 As Variant
Static v2 As String
value2 = Me.ComboBox2.Text
v2 = value2
End Sub

Private Sub ComboBox3_Change()
'fill items into combobox3
ActiveSheet.Shapes("ComboBox3").Select
Selection.ListFillRange = "R28:R37"
'copy the one selected item from combobox into a static value
Dim value3 As Variant
Static v3 As String
value3 = Me.ComboBox3.Text
v3 = value3
End Sub

//addnew function
Sub AddNew()

'Update data on Sheet1

Dim Vkey As Integer
Dim VDwgName As String
Dim VPathName As String
Dim VClassification As String
Dim VBuildingName As String
Dim VDwgType As String
Dim VLevel As String
Dim VYear As String
Dim VRegion As String
Dim VAsset As String

Dim VRow As Long
Dim VFound As Boolean

'MsgBox "The name of the active sheet is " & ActiveSheet.Name

'Before adding new entry, make sure a value was entered
If IsEmpty(Range("O2").Value) = False Then


'Retrieve new information
Vkey = Range("O2").Value
VDwgName = Range("O4").Value
VPathName = Range("O6").Value
'pass three static value into strings
VClassification = v1
VBuildingName = v3
VDwgType = v2

VLevel = Range("O14").Value
VYear = Range("O16").Value
VRegion = Range("O18").Value

'Move to Sheet1 to save the changes
'Sheets("Sheet2").Select

VFound = False

VRow = 87

Do While VFound = False

'Encountered a blank project number (assuming end of list on Sheet1)
If IsEmpty(Range("A" & VRow).Value) = True Then
VFound = True
End If

VRow = VRow + 1
Loop
'copy data into cells on the sheet
Range("A" & VRow - 1).Value = Vkey
Range("B" & VRow - 1).Value = VDwgName
Range("C" & VRow - 1).Value = VPathName
Range("D" & VRow - 1).Value = VClassification
Range("E" & VRow - 1).Value = VBuildingName
Range("F" & VRow - 1).Value = VDwgType
Range("G" & VRow - 1).Value = VLevel
Range("H" & VRow - 1).Value = VYear
Range("I" & VRow - 1).Value = VRegion
Range("J" & VRow - 1).Value = VAsset
Range("A" & VRow - 1).Value = Vkey
Range("B" & VRow - 1).Value = VDwgName
Range("C" & VRow - 1).Value = VPathName
Range("D" & VRow - 1).Value = VClassification
Range("E" & VRow - 1).Value = VBuildingName
Range("F" & VRow - 1).Value = VDwgType
Range("G" & VRow - 1).Value = VLevel
Range("H" & VRow - 1).Value = VYear
Range("I" & VRow - 1).Value = VRegion
Range("J" & VRow - 1).Value = VAsset

MsgBox ("New Entry was successfully added.")
End If

End Sub

5,172

社区成员

发帖
与我相关
我的任务
社区描述
其他开发语言 Office开发/ VBA
社区管理员
  • Office开发/ VBA社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧