我是Excel和vba的新手。
我有一个excel文件,其中包含一个按钮,可以执行以下单击的鼠标:
它会打开一个存储文件,复制列A数据,然后创建一个新的Excel文件并将复制的数据粘贴到其上
我尝试了以下代码,但我在selection.paste
行
Dim oExcel As Excel.Application
Dim oWB As Workbook
Set oExcel = New Excel.Application
'Set oWB = oExcel.Workbooks.Open("C:\Users\omran.alhammadi\Desktop\power ana\4EC73A75.WD0.xls")
Workbooks.Open Filename:="C:\Users\omran.alhammadi\Desktop\power ana\4EC73A75.WD0.xls"
Rows("1:9").Select
Selection.Delete Shift:=xlUp
Columns("A:A").Select
Selection.NumberFormat = "hh:mm:ss;@"
Columns("A:A").Select
Selection.Copy
'Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss;@"
Set NewBook = Workbooks.Add
With NewBook
.Title = "temp"
.Subject = "tempsub"
.SaveAs Filename:="Temp.xls"
End With
Workbooks("temp.xls").Activate
ActiveSheet.Columns("A:A").Select
Range("A1").Paste
Application.CutCopyMode = False
' NewBook("4EC73A75.WD0.xls").Activate
' Sheets("Sheet1").Activate
'*** Select the destination cell
' Range("A1").Select
' ActiveSheet.Range("A1").Paste
Workbooks("4EC73A75.WD0.xls").Close
答案 0 :(得分:1)
保存文件时清除剪贴板,因此粘贴方法失败。