BeforeDoubleClick以单元格值作为变量运行Macro

时间:2016-07-25 15:53:55

标签: sql excel excel-vba oracle-sqldeveloper vba

我在表格中的以下代码("查看代码")页面然后在我的模块页面中调用一个宏。双击变量是目标但由于某种原因它不会拉动它。

Private Sub GoBeforeDoubleClick3(ByVal Target As Range, Cancel As Boolean)


If Intersect(Target, Range("A3:A1000")) Is Nothing Then Exit Sub
    lot = Target.Value
    Cancel = True
    Call LSRPull

    'Worksheets("LSR").Activate
End Sub

我的前两个事件工作正常,因为它们很简单,转到页面宏。

Private Sub GoBeforeDoubleClick2(ByVal Target As Range, Cancel As Boolean)

    If Intersect(Target, Range("I3:I1000")) Is Nothing Then Exit Sub
        prc = Target.Value
        Cancel = True
        Worksheets("Tools").Activate
        ActiveSheet.Range("$A$2:$G$3000").AutoFilter Field:=2, Criteria1:=prc

End Sub


Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    On Error Resume Next
    GoBeforeDoubleClick1 Target, Cancel
    GoBeforeDoubleClick2 Target, Cancel
    GoBeforeDoubleClick3 Target, Cancel
    Application.EnableEvents = True
    End Sub

以下是Macro的代码:我不确定我是否想要构建到工作表页面或模块代码页中。

Sub LSRPull()
'
    Application.ScreenUpdating = False
    Application.Calculation = xlManual
    Dim sesOra As Object    'declare object variable to create instance to view database
    Dim dbOra As Object     'declare object variable to open database
    Dim rsOra As Object     'delcare object variable to create snapshot of database

    Dim SQL1 As String      'declare string variable of SQL query
    'Dim lottarget As String

    'Dim ADSCExclude As String

    Set sesOra = CreateObject("OracleInProcServer.XOraSession")     'sets up database session
    Set dbOra = sesOra.OpenDatabase("MFGINFO.World", "u_msas2/sa1sfby", 0)    'assign database for session

    Sheets("LSR").Select
    Range("$A$3:$M$65000").Select             'selects all possible previous data
    Selection.ClearContents




    SQL1 = " SELECT COUNT(reason) nmb, MAX(date), reason adsc, message_key tool "
    SQL1 = SQL1 + " FROM table"
    SQL1 = SQL1 + " WHERE date > sysdate - 1/24 "
    SQL1 = SQL1 + " AND inventory like  '%" & lot & "%' "
    SQL1 = SQL1 + " GROUP BY reason, message_key  "
    SQL1 = SQL1 + " ORDER BY MAX(date) DESC "


    Set rsOra = dbOra.DBCreateDynaset(SQL1, 0)  'sets up a snapshot of the query script that we have written
    rsOra.CopytoClipboard                       'copies snapshot of database to clipboard
    Sheets("LSR").Select
    On Error Resume Next
    Range("A3").PasteSpecial                    'pastes snapshot to excel
    Range("A3").Select




End Sub

0 个答案:

没有答案