Excel VBA – 分配单元格属性会抛出错误号1004

伙计们,我正努力从Excel工作表(名为“Kalender”)获得这段代码作为macros运行:

Public Function dcTest(s As String) As String Dim ws As Worksheet On Error GoTo dcTestExit Err.Clear Set ws = ActiveSheet ' Set ws = Worksheets("Kalender") '... same error (and yes, the sheet exists!) ' ws.Cells(2, 2).FormulaR1C1 = s ws.Cells(2, 2).Value = s dcTestExit: Set E = Err End Function 

一旦我尝试写入ValueFormulaR1C2属性,就会发生错误。 该函数被称为“用户自定义”function从一个Excel表格,如=dcTest("whatever")

你能把我指向正确的方向吗? RT(F)M欢迎只要细节…

干杯,ChrisF

UDF不允许直接更改任意位置的值。 请参阅VBA – 通过用户定义的函数更新其他单元以获得解决方法。