如何从word中调用工作表函数
我正在尝试从word中find最大的excel列,以前我用过
MyResult = application.Worksheetfunction.max (Range("B4:B7"))
从Excel中,现在我需要做的似乎从字面上的VBA。
但我不知道如何做到这一点,我需要做我自己的循环,并创build我自己的最大function?
maxVal =0 for i=2 to lastrow if xlapp.ws.cells(i,2)>maxVal then maxVal= xlapp.ws.cells(i,2) end if next i
我会先回答你提出的问题:
如何从word中调用工作表函数
像这样:
Dim excelApp As Object Set excelApp = CreateObject("Excel.Application") maxVal = excelApp.Worksheetfunction.max(1, 2, 3) 'Some values separated by comma or an array excelApp.Quit
现在你需要的只是最大function。 像这样:
Function MaxFunc(arr) Dim maxVal, tmpVal, ifFirst ifFirst = True For Each it In arr If ifFirst Then maxVal = it: ifFirst = False Else If maxVal < it Then maxVal = it End If Next MaxFunc = maxVal End Function
这里是我的代码基于来自AnlaystCave的input:
val(oXLApp.Worksheetfunction.Max( _ xlApp.Sheets("List").Range(xlApp.Sheets("List").Cells(3, columnWp), xlApp.Sheets("List").Cells(numofrows, columnWp))))