【发布时间】:2017-10-21 17:54:32
【问题描述】:
我有一个包含 1 个标题的电子表格,我正在尝试将数据从排除标题复制到另一个工作表中,该工作表位于另一个包含 2 个标题的工作簿中。我在网上找到了这个 sn-p 代码,但它给了我一个错误,指出第 25 行有一个预期的 ')'。
copyLastrow = ws1.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
这里:
searchorder:=xlByRows
这是脚本:
Const FILE1 = "C:\Users\roperalta\Desktop\Book1.xlsx"
Const FILE2 = "C:\Users\roperalta\Desktop\PBJ_Excel_to_XML_Template_v_2_00_3.xlsx"
Dim LastRow
Dim xlApp
Set xlApp = CreateObject("Excel.Application")
Dim wb1, wb2
With xlApp
.Visible = False
.DisplayAlerts = False
Set wb1 = .Workbooks.Open(FILE1, 0, False)
Set wb2 = .Workbooks.Open(FILE2, 0, False)
End With
Dim ws1, ws2
Set ws1 = wb1.Sheets("Sheet0 (2)")
Set ws2 = wb2.Sheets("Header")
ws2.Range("B3:D3").Value2 = ws1.Range("B2:D2").Value2
Set ws1 = wb1.Sheets("Sheet0")
Set ws2 = wb2.Sheets("Employees")
copyLastrow = ws1.Cells.Find("*", searchorder:=xlByRows, searchdirection:=xlPrevious).Row
pasteLastrowG = ws2.Range("A" & Rows.Count).End(xlUp).Row + 1
'pasteLastrowH ...
'pasteLastrowI ...
ws1.Range("J" & copyLastrow).Copy Destination:=ws2.Range("A" & pasteLastrowG)
'Copy and paste B code here
'Copy and paste C code here
wb2.Save
wb1.Close
'wb2.Close
'xlApp.Quit
Set ws1 = Nothing
Set ws2 = Nothing
Set wb1 = Nothing
'Set wb2 = Nothing
'Set xlApp = Nothing
【问题讨论】:
-
我不太了解VBScript,但也许它不允许命名参数?但是您还必须确保为
xlByRows、xlPrevious等设置值,因为这些常量通常由 Excel 库提供给 VBA 代码,但您使用的是 VBScript,因此没有库来定义那些常量。 -
像
Rows.Count这样的东西需要更改为ws2.Rows.Count,因为不合格的Rows对象不会被VBA 默认为Application.ActiveWorkbook.ActiveSheet.Rows,因为您没有使用VBA。 -
嗯,是的,可能是因为它是一个脚本,我从一个宏中找到了这个......我想知道是否有解决这个问题的方法?
-
@YowE3K 你是对的。没有名称参数。
-
解决方法是按照方法期望的顺序传递参数(不带“name:=”部分)。