excel 为什么分配给单元格的宏失败?

omvjsjqw  于 2023-06-25  发布在  其他
关注(0)|答案(2)|浏览(86)

我有一个宏分配给一个单元格,执行一次点击。宏涉及到SAP GUI脚本,如果中断(通过CTRL+DEL+ALT),也会导致我以前可单击的单元格停止工作。
我可以通过Developer运行宏,但单元格不工作。请注意,下面提供的代码粘贴在可单击单元格所在的工作表中,而不是ThisWorkbook中。

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal target As Range)

   If Selection.CountLarge = 1 Then
    
   If Not Intersect(target, Range("A10")) Is Nothing Then
       Call FolderPicker
   End If
    
End Sub

你知道是什么导致了这个问题吗?

neskvpey

neskvpey1#

您需要关闭所有if语句。

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal target As Range)

   If Selection.CountLarge = 1 Then

      If Not Intersect(target, Range("A10")) Is Nothing Then
       Call FolderPicker
      End If
   End If

End Sub
wfauudbj

wfauudbj2#

您可以用途:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

    'Check count how many cells affected to avoid errors
    If Target.Count = 1 Then

        If Not Intersect(Target, Range("A10")) Is Nothing Then
            Application.EnableEvents = False 'Disable events to avoid pointless code trigger
                Call FolderPicker
            Application.EnableEvents = True
        End If

    End If

End Sub

相关问题