VB.net如何等待用户选择Excel单元格
我在 Visual Studio 中创建了一个带有功能区和表单的 VSTO 项目。此表单上有一个按钮,当用户单击它时,它会等待用户从工作簿中选择使用此加载项的单个单元格。
我目前处于设计阶段,没有编写太多代码。实现这一目标有什么关键想法吗?我应该使用 Application.SendKeys 方法吗?还有其他/更好的想法吗?
感谢
到目前为止我的功能区代码:
Imports Microsoft.Office.Tools.Ribbon
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e
As RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As
RibbonControlEventArgs) Handles Button1.Click
Dim f As New Form1
f.Show()
End Sub
End Class
到目前为止我的表单代码:
Public Class Form1
'Variables for my "Custom Vlookup Function"
Dim RHeader As Excel.Range 'Reference Header
Dim SRange As Excel.Range 'Seleceted Range
Dim ColNo As Integer 'Column number ahead
Dim xlApp As Excel.Application = Globals.ThisAddIn.Application
Dim xlWB As Excel.Workbook =
Globals.ThisAddIn.Application.ActiveWorkbook
Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
End Sub
End Class
I have created a VSTO project in Visual Studio with a Ribbon and a Form. There is a button on this form which I want when a user clicks on it, it waits for user to select a single cell from the workbook which this add-in is used in it.
I am currently at designing stage and have not much code written. Any key ideas to achieving this? Should I use Application.SendKeys method? Any other/better ideas?
Thanks
My Ribbon Code so far:
Imports Microsoft.Office.Tools.Ribbon
Public Class Ribbon1
Private Sub Ribbon1_Load(ByVal sender As System.Object, ByVal e
As RibbonUIEventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As
RibbonControlEventArgs) Handles Button1.Click
Dim f As New Form1
f.Show()
End Sub
End Class
My Form Code so far:
Public Class Form1
'Variables for my "Custom Vlookup Function"
Dim RHeader As Excel.Range 'Reference Header
Dim SRange As Excel.Range 'Seleceted Range
Dim ColNo As Integer 'Column number ahead
Dim xlApp As Excel.Application = Globals.ThisAddIn.Application
Dim xlWB As Excel.Workbook =
Globals.ThisAddIn.Application.ActiveWorkbook
Private Sub Button2_Click(sender As Object, e As EventArgs)
Handles Button2.Click
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
等待 Worksheet.SelectionChange 事件当工作表上的选择发生更改时会触发。
Wait for the Worksheet.SelectionChange event which is fired when the selection changes on a worksheet.