简体   繁体   English

在Excel中单击单元格时是否可以运行SQL语句?

[英]Is it possible to run a SQL statement when a cell is clicked in Excel?

I'm trying to figure out if I am able to run a SQL statement when a user clicks on a cell in Excel. 我试图找出当用户单击Excel中的单元格时是否能够运行SQL语句。 If so how? 如果可以,怎么办?

Thanks, 谢谢,

Use the Worksheet SelectionChange method and you can do it! 使用工作表SelectionChange方法,就可以做到!

In this following code, the macro runs when you click A1 cell. 在下面的代码中,当您单击A1单元格时,宏将运行。

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

L = ActiveCell.Row
C = ActiveCell.Column

If L = 1 and C = 1 Then

*(write your code here)*

End if

End Sub

You can do something like this. 你可以做这样的事情。

Private Sub Worksheet_SelectionChange(ByVal Target As Excel.Range) 
    If Target.Address = "$A$1" Then 
        Call MyMacro 
    End If 
End Sub 

Then, fire off a Macro to do some kind of import or export. 然后,关闭宏以执行某种导入或导出操作。 That's what you want to do, right. 那就是你想做的,对。 Please see the links below for several ides of how to import and/or export data between Excel and Access. 请参阅下面的链接,以获取有关如何在Excel和Access之间导入和/或导出数据的一些指导。

http://www.erlandsendata.no/english/index.php?t=envbadac http://www.erlandsendata.no/english/index.php?t=envbadac

http://www.accessmvp.com/KDSnell/EXCEL_MainPage.htm http://www.accessmvp.com/KDSnell/EXCEL_MainPage.htm

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM