excel - 以编程方式向 Excel 添加和删除组合框
问题描述
虽然我没有困难以编程方式添加,但我无法删除组合框。在这段代码中,我尝试分配名称,但是当我尝试删除时,我无法以任何方式使用该名称。
当我尝试删除时,我也尝试使用手机号码,但它没有用。我很感激这个问题的帮助,这让我现在待了好几个小时:(
Set curCombo = Worksheets("Nodes").Shapes.AddFormControl(xlDropDown, Left:=Cells(i, 1).Left, Top:=Cells(i, 1).Top, Width:=100, Height:=Rows(2).RowHeight)
method_name = "Set_Node_Name"
With curCombo
.ControlFormat.DropDownLines = 44
.ControlFormat.ListFillRange = "Node_Type_Names!$A$1:$A$44"
.ControlFormat.LinkedCell = "B" & i
.OnAction = method_name
'.Name = "myCombo" & i
End With
解决方案
使用Intersect
您可以确定组合框是否在您要删除的范围内。
我在这里使用 B 列。
Sub removeCombos()
Dim combo As DropDown
Dim irng As Range
With ActiveSheet
For Each combo In .DropDowns
Set irng = Application.Intersect(combo.TopLeftCell, .Range("B:B"))
If Not irng Is Nothing Then
combo.Delete
End If
Next
End With
End Sub
推荐阅读
- sql - Oracle SQL-插入语句-SQL 错误:ORA-00984:此处不允许列
- react-native - textContentType=oneTimeCode 不适用于 iOS
- c++ - 如何在结束 C++ 命令行应用程序时运行函数?
- php - 这个 PHP 类常量声明有什么问题?
- reactjs - npm run build - 尽管开发版本工作正常,但无法编译
- node.js - 无法在 Webpack 3 中将 Sass 添加到 Vue 项目
- javascript - 如何使用 Javascript 计算 Acrobat PDF 中的字段?
- react-native - 如何将原生 ios 第三方库集成到 React Native 应用程序中?
- python - 在包中使用动态文件
- jinja2 - saltstack jinja for 并行循环