简体   繁体   中英

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.

Basically there is a form that has several buttons that call a public function called "writeEntry" which is stored in a module called "describePhotosExcel". The code breaks no matter where writeEntry is called from.

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. 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":

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. Therefore when it saw the word test it thought I was referring to this subroutine and not a new variable I was throwing away. Deleted that and it works well now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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