Consulting

Results 1 to 5 of 5

Thread: Solved: Disfunctional Function Statement

  1. #1
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location

    Solved: Disfunctional Function Statement

    Ok, this is embarrassing. I'm trying to add a function to some code and I'm getting a compile error: "Expected End Sub" with the End Function line highlighted and the execution line showing as function statement line. If I remove the function/end function statements and just set iEngHours, everything is fine.

    I seem to have trashed my VBA help too (hangs on opening), but that's a separate problem...

    Here is the code, any ideas?
    [VBA]
    Private Sub cmdHourQuote_Click()
    Dim iEngHours As Integer

    iEngHours = ProjectHours()

    If iEngHours > 0 Then
    MsgBox "This project will take approximately" & vbCrLf _
    & Str(iEngHours) & " hours.", vbOKOnly + vbInformation, "Quick Hour Quote"
    End If

    End Sub
    Private Function ProjectHours() As Integer
    ProjectHours = 1
    End Function
    [/VBA]

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Your code works fine for me as is on Word 2002. You may need to reinstall office (given the problem with VBA help crashing as well).

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Works for me in 2000. Re the VBA help crash, I get that often. In Task Manager, shut the TWO msohelp processes to clear the problem.
    MD

  4. #4
    VBAX Regular village_alchemist's Avatar
    Joined
    Jul 2004
    Location
    Michigan, US
    Posts
    32
    Location
    MD, thanks for the suggestion. That will be faster than re-installing office again. The re-install fixed the help issue, but not the expected end sub issue. In fact the problem kept getting worse until I finally realized that I had a macro virus. Seems one of the salesmen in my company sent me a nice little virus as gift and it infected my Normal template. Renamed (and subsequently deleted) the normal template and let word create a new one. All is well!

  5. #5
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    Quote Originally Posted by village_alchemist
    ... a nice little virus as gift ...
    Sounds like a nice gift!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •