gpt4 book ai didi

excel - 获取 Excel 中选定范围内可用的事件单元格?

转载 作者:行者123 更新时间:2023-12-02 16:23:46 25 4
gpt4 key购买 nike

我正在使用 VSTO。在这种情况下,单击 Excel 工作表的按钮将显示输入框,我将获得选定的范围。我想知道如何从输入框中获取 Excel 工作表的事件单元格地址的选定范围。

object objInputBox= Excel.Application.InputBox(prompt, field, Type.Missing, Type.Missing,
Type.Missing, Type.Missing, Type.Missing, 8);
ExcelXP.Range selectedRange = objInputBox as Excel.Range;

string rangeName = selectedRange.get_Address(Type.Missing, Type.Missing, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

string activeCell =Application.Application.ActiveCell.get_Address(true, true, Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing);

如何获取 rangeName 中的事件单元格地址?

提前致谢

最佳答案

以下是使用 Application.Intersect 实现此目的的方法。示例是 VBA,但可以轻松移植到 C#。

Sub TestinRange()
Dim inputRange As Range
Set inputRange = Worksheets(1).Range("B1:B5")
Dim IsActiveCellInInputRange As Range
Set IsActiveCellInInputRange = Application.Intersect(inputRange, ActiveCell)
If IsActiveCellInInputRange Is Nothing Then
Debug.Print "Nope, the ActiveCell is not within the Input Range"
Else
Debug.Print "Yep, the ActiveCell is within the Input Range. ActiveCell Address: " & ActiveCell.Address
End If
End Sub

关于excel - 获取 Excel 中选定范围内可用的事件单元格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3656187/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com