是否可以通过VBA恢复Excel中的pastepecial动作的参数?

发布于 2025-02-03 06:56:57 字数 1915 浏览 2 评论 0原文

有没有办法“听” Excel中的“聆听the the the the the the the the the the the the the the the the the the pastepecial命令及其参数? 我正在编写一个VBA代码来管理范围。PasteSpecial方法,并意识到我需要一种方法来知道用户定义的操作的转置参数是对还是错,因此我可以相应地对待源数据。 奥斯科派对,因为我不知道何时transpose是正确的,所以下面的这条代码实际上无效。

Private Sub Worksheet_Change(ByVal Target As Range)
Dim UndoList As String

Application.ScreenUpdating = False
Application.EnableEvents = False

If Application.CommandBars("Standard").Controls("&Undo").Enabled = True Then

   UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
   MsgBox (UndoList & "!")
     If Left(UndoList, 5) = "Paste " Or UndoList = "Paste special" Then
        
        If UndoList = "Paste special" Then
            If Transpose Then
            MsgBox ("Paste Transposed Values")
             Application.EnableEvents = False
             Application.Undo
             Application.EnableEvents = True
             Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
             'and other stuff
            Exit Sub
            Else
            MsgBox ("Paste Values")
             Application.EnableEvents = False
             Application.Undo
             Application.EnableEvents = True
             Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
             'and other stuff
            Exit Sub
         End If
         ElseIf Left(UndoList, 5) = "Paste" Then
        MsgBox ("Just Paste formats")
        Application.EnableEvents = False
            Application.Undo
            Application.EnableEvents = True
            Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False

        Exit Sub

     Else
        MsgBox ("choose another method")
         'Application.Undo
     Exit Sub
     End If
Else
Exit Sub
End If
UndoList = ""
End If
End Sub




is there a way to "listen' to the PasteSpecial command and its parameters in excel?
I'm writing a vba code to manage the Range.PasteSpecial method and realized I need a way to know if the Transpose parameter of the action defined by the user is true or false, so I can treat the source data accordingly.
Offcourse, since I don't know when Transpose is TRUE, this piece of code below does not really work.

Private Sub Worksheet_Change(ByVal Target As Range)
Dim UndoList As String

Application.ScreenUpdating = False
Application.EnableEvents = False

If Application.CommandBars("Standard").Controls("&Undo").Enabled = True Then

   UndoList = Application.CommandBars("Standard").Controls("&Undo").List(1)
   MsgBox (UndoList & "!")
     If Left(UndoList, 5) = "Paste " Or UndoList = "Paste special" Then
        
        If UndoList = "Paste special" Then
            If Transpose Then
            MsgBox ("Paste Transposed Values")
             Application.EnableEvents = False
             Application.Undo
             Application.EnableEvents = True
             Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=True
             'and other stuff
            Exit Sub
            Else
            MsgBox ("Paste Values")
             Application.EnableEvents = False
             Application.Undo
             Application.EnableEvents = True
             Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
             'and other stuff
            Exit Sub
         End If
         ElseIf Left(UndoList, 5) = "Paste" Then
        MsgBox ("Just Paste formats")
        Application.EnableEvents = False
            Application.Undo
            Application.EnableEvents = True
            Selection.PasteSpecial Paste:=xlPasteFormats, Operation:=xlNone, SkipBlanks:=False

        Exit Sub

     Else
        MsgBox ("choose another method")
         'Application.Undo
     Exit Sub
     End If
Else
Exit Sub
End If
UndoList = ""
End If
End Sub




如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文