【发布时间】:2014-10-06 01:55:58
【问题描述】:
我正在尝试整理一个主电子表格,该电子表格从 100 多个包含各种数据的工作簿中提取。我无法弄清楚如何访问已关闭的工作簿以计算其中一行的标准偏差。
Sub RefreshSourceData()
Dim sourceFile, fileName As String, path As String
Dim dispersionRange As Range
path = "U:\SPACE Info\Meeting Materials\Strategy Files\"
fileName = "[" & ActiveCell.EntireRow.Cells(1, 1).Value & ".xls]"
sourceFile = "=" & path & fileName
dispersionRange = "=" & path & fileName & "Account'!R:R"
Range("B" & ActiveCell.Row).Formula = sourceFile & "Summary'!$F$2"
Range("C" & ActiveCell.Row).Formula = sourceFile & "Summary'!$F$3"
Range("D" & ActiveCell.Row).Formula = sourceFile & "Summary'!$B$10"
Range("E" & ActiveCell.Row).Formula = sourceFile & "Summary'!$D$10"
Range("F" & ActiveCell.Row).Formula = WorksheetFunction.StDev(dispersionRange)
End Sub
我收到了各种错误,现在是“对象变量或未设置对象变量。”
我也尝试过创建一个包含路径和文件名的工作簿变量,但这也没有奏效。
【问题讨论】:
-
可能最简单的方法是使用 VBA 打开每个工作簿 (
workbooks.open),进行计算,关闭工作簿,然后转到下一个工作簿。您当前的错误正在发生,因为您没有“设置”dispersionRange。
标签: vba excel statistics