简体   繁体   English

VBA Excel - 编译错误 - 预期 function 或变量

[英]VBA Excel - Compile Error - Expected function or variable

It's probably something simple but I have been trying to work out how to fix a compile error I am getting with an excel document I have created for a while now and I have not made any progress.这可能很简单,但我一直在尝试解决我在创建一段时间后的 excel 文档时遇到的编译错误,但我没有取得任何进展。

Basically there is a form that has several buttons that call a public function called "writeEntry" which is stored in a module called "describePhotosExcel".基本上,有一个表单有几个按钮,这些按钮调用一个名为“writeEntry”的公共 function,它存储在一个名为“describePhotosExcel”的模块中。 The code breaks no matter where writeEntry is called from.无论从哪里调用 writeEntry,代码都会中断。

So far I have tried calling the function from different subs, changing the subs from private to public, adding the module name before the function and renaming the function... I'm not quite sure what else I can do.到目前为止,我已经尝试从不同的子系统调用 function,将子系统从私有更改为公共,在 function 之前添加模块名称并重命名 ZC1C425268E68385D14AB5074C17A 不知道还有什么...... Any help would be much appreciated.任何帮助将非常感激。

Code from the form:表格中的代码:

Private Sub PrevPhotoBTN_Click()
   wrow = CInt(PhotoDataEntry.CurrentRow.Caption)
   test = writeEntry(wrow, Direction.Text, RoadCombo.Text, Chainage.Text, Location.Text, CommentsCombo.Text, Condition.Text)
   wrow = CInt(PhotoDataEntry.CurrentRow.Caption) - 1
   PhotoDataEntry.CurrentRow.Caption = wrow
   temp = PopulatePhotoForm()
End Sub

Code from the module "describePhotosExcel":来自模块“describePhotosExcel”的代码:

Public Function writeEntry(CurrentRow, Dir, RoadName, Chainage, Optional Title = "", Optional Comments = "", Optional Rating = "", Optional PhotoNumber = "") As Variant
    Application.Workbooks(PhotoDataEntry.WBK.Caption).Activate
    Worksheets("Data").Activate

    Cells(CurrentRow, 6) = Dir
    Cells(CurrentRow, 8) = RoadName
    Cells(CurrentRow, 9) = Chainage
    Cells(CurrentRow, 10) = Title
    Cells(CurrentRow, 11) = Comments
    Cells(CurrentRow, 14) = Rating
    Cells(CurrentRow, 13) = PhotoNumber
    writeEntry = 1
End Function

So I worked it out.所以我解决了。

I had created a subroutine called "test" which was used to do some testing.我创建了一个名为“test”的子程序,用于进行一些测试。 Therefore when it saw the word test it thought I was referring to this subroutine and not a new variable I was throwing away.因此,当它看到 test 这个词时,它以为我指的是这个子例程,而不是我要丢弃的新变量。 Deleted that and it works well now.删除了它,它现在运行良好。

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

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