如何复制组合框以便单元格链接自动更改
是否可以复制创建的组合框并将其粘贴到另一个单元格中,以便 该单元格链接也更改了吗?
我使用 Excel 2007 进行这项工作。
示例:我在 A5 中有组合框,单元格链接指向 B5。我想复制 组合框指向单元格 A4,单元格链接指向 B4。
我需要复制 50 多个组合框。当我按下包含宏的命令按钮来复制整行并将其全部插入到新行时,我尝试使用它。
我找到了一个答案,但 VBA 显示“编译错误:用户定义的类型未定义!”并且“TypeOf cbo.Object Is msforms.ComboBox”为粗体。
我发现的宏:
Sub Test()
Dim cbo As OLEObject
For Each cbo In ActiveSheet.OLEObjects
If TypeOf cbo.Object Is msforms.ComboBox Then
cbo.LinkedCell = cbo.TopLeftCell.Offset(, 1).Address
End If
Next
End Sub
Is it possible to copy a created combobox and paste it in another cell so
that cell link is changed too?
I do this work with Excel 2007.
Example: I have combobox in A5, cell link pointing to B5. I want to copy
the combo box to cell A4 and the cell link to point to B4.
I need to copy more than 50 comboboxes. I tried to use it when I push the commandbutton which include the macro to copy a entire row and insert all of it to the new row.
I found one answer but VBA showed "Compile error: User defined type not defined!" and "TypeOf cbo.Object Is msforms.ComboBox" is bold.
Macro I found:
Sub Test()
Dim cbo As OLEObject
For Each cbo In ActiveSheet.OLEObjects
If TypeOf cbo.Object Is msforms.ComboBox Then
cbo.LinkedCell = cbo.TopLeftCell.Offset(, 1).Address
End If
Next
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最初的答案让我走上了正轨,适用于“ActiveX 控件”。我需要使用标准 Excel“表单控件”组合框执行相同的操作,它非常相似,只是它是一个形状对象并且需要选择它才能进行操作。这是我的代码,对我有用:
The original answer put me on the right track and works for the "ActiveX control". I needed to do the same thing with a standard Excel "Form control" combobox and it's pretty similar, except it's a shape object and it needs to be selected to be manipulated. Here's my code, which worked for me:
Reima,
如果您使用“控件工具箱”工具栏中的控件,则以下内容应该有效。唯一的区别是它不是 MSForms.Combobox。 :
如果您使用“表单”工具栏中的组合框,那么我不确定最好的方法是什么。我想尝试使用上面的方法。
Reima,
If you are using controls from the "Control Toolbox" toolbar, then the following should work. The only difference is that it's not an MSForms.Combobox. :
If you are using a combobox from the "Forms" toolbar, then I'm not sure what the best approach is. I'd try using the method above.