访问错误“sub或function not defined”

时间:2015-12-23 11:27:24

标签: vba ms-access

我在运行VBA访问时出错。 当我运行此代码时

Option Compare Database

Function Ashray()

Dim last As String
Dim i As Integer
Dim column As Integer
Dim temp As String

column = 2
i = 1

While i > 0
temp = ws.Cells(i, column).Value
last = Right(temp, 4)
ws.Cells(i, 1).offset(, column).Value = last
i = i + 1
If ws.Cells(i, column).Value < 1 Then
i = 0
End If

Wend
End Function

我收到错误Run-time Error '424': Object Requiredtemp = ws.Cells(i, column).Value粗体。

我会很高兴得到一些帮助..

谢谢

3 个答案:

答案 0 :(得分:1)

Cells是一个Excel对象,它在Access中不存在。

如果您有工作表变量,请将其用作限定符:

ws.Cells

答案 1 :(得分:0)

请检查您的代码

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="chat-area">
  <div id="dialogContent" title="This is a dialog box">
    <header>
      <h2> Chat Dialog Header</h2>
      <span class="chat-cancel">X</span>
    </header>
    <textarea rows="14" cols="40" name="comment" id="comment"></textarea>
    <button class="chat-cancel"> Cancel  </button>
    <button class="chat-save" type="submit"> Save  </button>
  </div>
  <div class="editButton">Chat</div>
</div>

这不是Wend,这可能是End While。

此致 Jasbeer Singh

答案 2 :(得分:0)

我想您忘记在项目中添加Microsoft Excel 15.0对象库引用(工具&gt;参考,然后检查我提到的库)。 然后尝试实例化Excel对象:

Option Compare Database

Function Ashray()

Dim last As String
Dim i As Integer
Dim column As Integer
Dim temp As String
Dim ws As Excel.Application
Dim wsht as ws.Workbook

Set wsht = Workbooks("yourWorkbook.xls").Sheets("yourSheet")
column = 2
i = 1

While i > 0
temp = wsht.Cells(i, column).Value
last = Right(temp, 4)
wsht.Cells(i, 1).offset(, column).Value = last
i = i + 1
If wsht.Cells(i, column).Value < 1 Then
i = 0
End If
Wend

End Function

您必须将库添加到Access项目,否则它将找不到您尝试访问的Excel工作簿。

问候。