我目前正在尝试创建.vbs
这是我到目前为止所做的:
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("C:\test\test.xlsm", 0, True)
xlApp.Run "test"
xlbook.Save
xlBook.Close False
set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
WScript.Echo "Upload is Finished"
WScript.Quit
我得到了“上传已完成”,但未保存该宏。我做错了什么?
宏只是将一个工作表中的内容放到另一个工作表中:
Sub test()
'
' test Macro
'
Sheets("Sheet2").Select
Range("A1:A10").Select
Range("A10").Activate
Selection.Cut
ActiveSheet.Previous.Select
Selection.End(xlToLeft).Select
Range("A2").Select
ActiveSheet.Paste
End Sub
答案 0 :(得分:2)
出于好奇为什么Excel中的宏?如果您通过对象控制Excel,为什么还没有宏代码?
Dim xlApp, xlBook
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = False
Set xlBook = xlApp.Workbooks.Open("C:\test\test.xlsm", 0, True)
xlbook.Sheets("Sheet2").Range("A1:A10").Cut
xlbook.Sheets("Sheet2").Previous.Select
xlbook.Range("A2").Paste
xlbook.Save
xlBook.Close False
set xlBook = Nothing
xlApp.Quit
Set xlApp = Nothing
WScript.Echo "Upload is Finished"
WScript.Quit
答案 1 :(得分:2)
xlBook.Close False
表示"关闭并且不保存更改"。也许你想要
xlBook.Close SaveChanges:=True