1

我收到了这个错误

runtime error 1004 in VB "method cells of object global_failed"

这些是我的代码:

Set oXL = EDOffice1.GetApplication()

Dim oWB As Excel.Workbook

Set oWB = EDOffice1.ActiveDocument()

Dim oSheet As Excel.Worksheet

Dim oRng As Excel.Range

Dim SUM As Long

Set oSheet = oWB.ActiveSheet


Range("F1").Formula = "=SUM(" & Range(Cells(2, 2), Cells(25, 2)).Address(False, False) & ")"

请帮忙。

4

2 回答 2

1

也许您不在sheet代码中,Cells无需参考工作表即可调用。

尝试确定您要执行此操作的工作表并使用:

Sheet.Range("F1").Formula = "=SUM(" & Sheet.Range(Sheet.Cells(2, 2), Sheet.Cells(25, 2)).Address(False, False) & ")"
于 2013-05-06T20:09:00.823 回答
0

试试这个(未经测试)

将行更改Range("F1").Formula = "=SUM(" & Range(Cells(2, 2), Cells(25, 2)).Address(False, False) & ")"

With oSheet 
    .Range("F1").Formula = "=SUM(" & _
                           .Range(.Cells(2, 2), .Cells(25, 2)).Address(False, False) & _
                           ")"
End With
于 2013-05-06T20:08:04.573 回答