VBA:禁用源工作簿中的宏

时间:2016-07-28 01:17:55

标签: excel vba autofilter

如何在“源工作表”中禁用宏?

With ThisWorkbook                                 ' enable this workbook
    Sheets.Add.Name = "Flow_table"                ' add worksheet to be used here
    Sheets.Add.Name = "TP_loc"                    ' add worksheet to be used here
    ActiveSheet.Range("A1").Value = TextBox1.Value    'get the location of the source
    ActiveSheet.Range("B1").Value = TextBox2.Value


    Set Source = Workbooks.Open(TextBox1.Value)
    Set Source_flow = Source.Worksheets(TextBox2.Value).Columns("A:L")
    Set target_flow = ThisWorkbook.Worksheets("Flow_table").Columns("A:L")

    ' **Insert a code here that will disable the MACRO of Source which is the source workbook**

    Source_flow.Copy Destination:=target_flow     ' copy source worksheet
    Source.Close False

End With

1 个答案:

答案 0 :(得分:2)

您似乎正在尝试阻止事件过程运行。你可以使用以下方法阻止那些射击:

Application.EnableEvents = False

然后在您完成后重置:

Application.EnableEvents = True