Excel剪贴板清除



我是编写excel宏的新手,但我很难完成任务。无论如何,我正试图将数据从2个工作表导出到另一个工作簿中的另外2个工作单,但当我达到清除剪贴板的地步时,它根本不起作用:(有人能帮我吗?这是我的代码:

Sub manufacturer_export()
Dim Return_Shipment_Template_Proba As Workbook
Dim wbTarget As Workbook
Dim activeSht As Worksheet
    Set Return_Shipment_Template_Proba = ThisWorkbook
    Set wbTarget = Workbooks.Open("file:///F:FEM Backup20.07.20168_GT Returns & Sample tracking1_Returns SummaryReturns Summary.xlsm")
Set activeSht = Return_Shipment_Template_Proba.Sheets("GT_GU10_Lamp")
    With Return_Shipment_Template_Proba.Sheets("GT_GU10_Lamp").Range("A3:X3")
' Column B may be empty. If so, xlDown will return cell C65536
' and whole empty column will be copied... prevent this.
        If .Cells(1, 24).Value = "" Then
    'Nothing in this column.
    'Do nothing.
    Else
    Return_Shipment_Template_Proba.Sheets("GT_GU10_Lamp").Range(.Cells(1, 24), .End(xlDown)).Copy
    wbTarget.Sheets("GT_GU10_Lamp").Activate
    ActiveCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=True, Transpose:=False
End If
End With
Application.CutCopyMode = False
Set activeSht = Return_Shipment_Template_Proba.Sheets("GT_COB_GU10_Lamp")
With       Return_Shipment_Template_Proba.Sheets("GT_COB_GU10_Lamp").Range("A3:X3")
' Column B may be empty. If so, xlDown will return cell C65536
' and whole empty column will be copied... prevent this.
    If .Cells(1, 24).Value = "" Then
    'Nothing in this column.
    'Do nothing.
        Else
    Return_Shipment_Template_Proba.Sheets("GT_COB_GU10_Lamp").Range(.Cells(1, 24), .End(xlDown)).Copy
    wbTarget.Sheets("GT_COB_GU10_Lamp").Activate
    ActiveCell.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=True, Transpose:=False
End If
End With
wbTarget.Save
End Sub

使用API调用的替代方法,您可以使用它来清除windows剪贴板:

Private Sub ClearClipboard()
    CreateObject("WScript.Shell").Run "CMD /C @ECHO OFF | CLIP", 0, False
End Sub
'// Example
Sub Foo()
'// Do something here...
ClearClipboard
'// clipboard is now empty
End Sub

这是一个64位代码,用于使用API的:清除剪贴板

坦率地说,你的错误不在剪贴板中(见我的评论),但这里是:

Option Explicit
'Open the clipboard to read
Private Declare PtrSafe Function OpenClipboard Lib "user32" (ByVal hwnd As LongPtr) As Long
'clear clipboard
Public Declare PtrSafe Function EmptyClipboard Lib "user32" () As Long
'Close the clipboard
Private Declare PtrSafe Function CloseClipboard Lib "user32" () As Long


Sub Clear_Clipboard()
OpenClipboard (0&)
EmptyClipboard
CloseClipboard
Application.CutCopyMode = False
End Sub

最新更新