我是编写 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 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
除了使用 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)