簡體   English   中英

vba 宏未自動運行

[英]vba Macro not Running Automatically

當活動單元格更改時,我無法讓我的宏在 Excel 中自動運行。 這是我正在使用的代碼。 當我 go 到開發人員選項卡和 select 宏並運行它時,它可以工作。 誰能幫我設置它,以便在更改單元格時自動運行?

Sub didcellschange()
Dim KeyCells As String
KeyCells = "e14"
If Application.Intersect(activecell, Range("e14")) Is Nothing Then breakbarcode

End Sub


Sub breakbarcode()
'this macro breaks the barcode from the labels. it also compares the expiration date and P/N
Application.DisplayAlerts = False
ActiveSheet.Unprotect
activecell.Select
Selection.TextToColumns destination:=activecell.Offset(0, 0), DataType:=xlDelimited, 
consecutivedelimiter:=True, semicolon:=True
If (UCase(activecell.Offset(0, 0)) <> UCase(activecell.Offset(0, -1))) Then MsgBox "Wrong Component"
If (UCase(activecell.Offset(0, 2).Value - 31 < prepdate)) Then MsgBox "Attention: This material is 
either expired or will expire soon. Please requalify or order new material."
activecell.Offset(0, 4).Select
ActiveSheet.Protect


End Sub
' In your Worksheet code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Not Intersect(Target, Target.Worksheet.Range("E14")) Is Nothing Then 
        Application.EnableEvents = False
        breakbarcode
    Application.EnableEvents = True
    End If
End Sub

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM