我是写excel宏的新手,但我很难完成任务。无论如何,我正在尝试将数据从2个工作表导出到另一个工作簿中的另外2个工作表,但是当我到达清理剪贴板时,它根本不起作用:(有人可以帮我吗?这是我的代码:< / p>
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 Backup\20.07.2016\08_GT Returns & Sample tracking\01_Returns Summary\Returns 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
答案 0 :(得分:0)
使用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
答案 1 :(得分:-1)
这是一个64位代码,用于清除剪贴板,使用API&#39>:
坦率地说,你的错误不在剪贴板中(请参阅我的评论),但这里有:
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