How should I fix this code because it throws: "The object doesn't support this property or method"
Sub macro1()
    Workbooks("OUTPUT.xls").She开发者_如何学Pythonets("Sheet1").Activate
    ActiveSheet.Range("B4") = _ 
    Workbooks("INPUT.xlsx").Sheets("Sheet1").Sum(Range("D40:D50"))
End Sub
Above code works fine when adjusted as:
Sub macro2()
    Workbooks("OUTPUT.xls").Sheets("Sheet1").Activate
    ActiveSheet.Range("B4") = _
    Workbooks("INPUT.xlsx").Sheets("Sheet1").Range("D40")
End Sub
However it's not acceptable solution because I want to Sum() over Range() as described in macro1().
try
ActiveSheet.Range("B4").Formula = Application.WorksheetFunction.Sum(Range("D40:D50"))
WorkSheet doesn't have a sum function, try using WorksheetFunction instead:
Sub macro1() 
    Workbooks("OUTPUT.xls").Sheets("Sheet1").Activate
    ActiveSheet.Range("B4") = _
        Application.WorksheetFunction.Sum(Workbooks("INPUT.xlsx").Sheets("Sheet1").Range("D40:D50"))
End Sub 
 
         
                                         
                                         
                                         
                                        ![Interactive visualization of a graph in python [closed]](https://www.devze.com/res/2023/04-10/09/92d32fe8c0d22fb96bd6f6e8b7d1f457.gif) 
                                         
                                         
                                         
                                         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论