繁体   English   中英

我的VBA没有返回任何错误,但不会在MS-Excel中设置单元格的值

[英]My VBA isn't returning any errors but wont set the value of a cell in MS-Excel

我无法弄清楚为什么我的程序不会按照我的预期去做。 我使用了非常相似的代码在程序的其余部分中设置值,但是对于此特定设置,该代码将无法正常工作。

public sub setValue(wrkBook as object, wrkSht as object)
    dim CurCell as object
    wrkSht = wrkbook.Sheets("TestSheet")
    Set curCell = wrkSht.Cells(4,1)
    CurCell.Value = "Test"
end sub

没有错误返回。 我只是简单地不将cell(4,1​​)的值设置为“ test”。 我正在Access内部使用VBA

wrkShrwrkSht不同

Public Sub setValue(wrkBook As Object)
    Dim CurCell As Range, wrkSht As Worksheet
    Set wrkSht = wrkBook.Sheets("TestSheet")
    Set CurCell = wrkSht.Cells(4, 1)
    CurCell.Value = "Test"
End Sub

注意:

除了拼写之外,我们还更正了Dim ,并使用Set创建了工作表对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM