简体   繁体   中英

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. If so how?

Thanks,

Use the Worksheet SelectionChange method and you can do it!

In this following code, the macro runs when you click A1 cell.

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.

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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