2016-07-28 148 views
1

如何禁用“源工作表”中的宏?VBA:禁用源工作簿中的宏

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 

回答

2

它看起来像你试图阻止事件过程运行。您可以通过阻止那些来自射击:

Application.EnableEvents = False 

,然后当你完成重置:

Application.EnableEvents = True 
+0

感谢。我会检查这一个。 :) @ThunderFrame –

+0

很酷。谢谢@Thomas Inzina –

+0

嗨@ThunderFrame,我试过这个,但源工作簿中的宏仍与我的宏冲突。 –