将单元格从一个工作簿复制到另一个工作簿,但是在运行时不工作

我正在编写一个从活动工作簿(订单)抓取特定单元格的子工具,打开指定的工作簿(报表),并按特定顺序删除这些值。 奇怪的是,这工作得很好,当通过,我可以看到报告工作簿打开和值填充,但运行时打开工作簿,但似乎并没有改变它。

代码如下(有点粗糙和准备好,我还在学习…)

Sub TransferTheData() Dim mySheet As Worksheet, myOtherSheet As Worksheet Dim myOtherBook As Workbook Dim i As Integer, j As Integer Dim vToday As String Set myOtherBook = Workbooks.Open("c:\\Test\Test Report.xlsx") Set mySheet = ThisWorkbook.Sheets("Order Form") Set myOtherSheet = myOtherBook.Sheets("Sheet1") vToday = Format(Date, "dd/mmmm/yyyy") j = myOtherSheet.Range("A" & Rows.Count).End(xlUp).Row + 1 For i = 18 To 85 If mySheet.Cells(i, 1).Value <> "" Then 'Loop through 68 rows and copy values myOtherSheet.Cells(j, 3).Value = mySheet.Cells(i, 1).Value myOtherSheet.Cells(j, 4).Value = mySheet.Cells(i, 2).Value myOtherSheet.Cells(j, 5).Value = mySheet.Cells(i, 3).Value 'constant values copied to each row in report sheet myOtherSheet.Cells(j, 1).Value = mySheet.Cells(5, 2).Value myOtherSheet.Cells(j, 2).Value = mySheet.Cells(9, 5).Value myOtherSheet.Cells(j, 8).Value = vToday myOtherSheet.Cells(j, 6).Value = mySheet.Cells(9, 2).Value myOtherSheet.Cells(j, 7).Value = mySheet.Cells(6, 2).Value j = j + 1 End If Next i End Sub 

任何人都可以看到我哪里出了错? 一直在看它几个小时我的头…

很典型的是,在看了几个小时然后发布一个问题之后,我在这里find了答案!

这个线程讨论并回答这个问题。 键盘快捷键没有使用工作簿对象的Open方法(我认为)的Shift键:

shift键使得vb脚本在任何Open语句处停止。

为.add切换.open,我们正在按照预期滚动function全部! 🙂