我已将地图放入建筑座位表的优秀位置,并在有人坐的每个位置创建了activeX文本框。我还列出了每个座位和坐在那里的人。我想要做的是浏览列表并为每个人分配正确的文本框名称。每个文本框的名称是“TextBox____”,其中空白是座位名称“。我在”set tbox“行中收到错误。
Sub UpdateMap()
Dim name As Variant
Dim tbox As MSForms.TextBox
Dim rng As Range
Dim cell As Range
With ThisWorkbook.Worksheets("5th floor map")
Set rng = .Range("A2:A5")
For Each cell In rng
ws = cell.Value
name = Application.VLookup(ws, .Range("A2:B5"), 2, False)
Set tbox = ThisWorkbook.Worksheets("5th floor map").Shapes("TextBox" & ws)
tbox.Value = name
Next
End With
End Sub
我只使用了这个例子的前四个名字/席位,并使用了for循环,因为实际上有超过100个。关于如何使这项工作的任何建议将不胜感激。或者,如果我认为这完全错了,请告诉我。感谢。
答案 0 :(得分:0)
试试这个
Sub UpdateMap()
Dim rng As Range
Dim cell As Range
With ThisWorkbook.Worksheets("5th floor map")
Set rng = .Range("A2:A5")
For Each cell In rng
.OLEObjects("TextBox" & cell).Object.Text = cell.Offset(0, 1).Value
Next
End With
End Sub
答案 1 :(得分:0)
试试这个
Sub oo()
Dim ol As OLEObject
Set ol = ThisWorkbook.Worksheets("MySheet").OLEObjects("TextBox1")
With ol
.Object.Text = "blabla"
.Object.ForeColor = RGB(0, 0, 192)
.Object.BorderStyle = fmBorderStyleSingle
.Object.SpecialEffect = fmSpecialEffectFlat
.Object.BackColor = RGB(192, 192, 192)
'.object.....
End With
End Sub