• Compile Error when closing workbook via code (2002)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Compile Error when closing workbook via code (2002)

    Author
    Topic
    #391799

    I have code within an Excel Addin that modifies code in 2 events of the ThisWorkbook module in a seperate workbook. The code is modified correctly and without error and executing the wb.save method works with no problem. If however I call wb.close I get a Compile Error stating that there is an End If Without Block If. If I do not call the close method and at the endof the code execution manually close the workbook (not using code) there is no error. Bottom line is that the If statement is solid and not missing any syntax but trying to close the workbook via code trips the error. Any ideas? If anyone has any sugesstions on what keywords to use for a Google search on this that would be fine as well.

    Thanks
    Ed

    Viewing 1 reply thread
    Author
    Replies
    • #701159

      I have got this error message when, in fact, there have been other things, like an “End With” etc, missing. Have you tried running the Workbook.Close piece on its own – commenting out all the pieces of the procedures? HTH

      • #701162

        I have not however if I comment out the close method and then manually colse the xls file via the menus after the code has completed there is no error. I can even compile it via the menus and there are no errors. It’s definately something to d with the ifference between closing the file via code verses doing so through the Excel application interface.

        Thanks
        Ed

    • #701168

      Any chance you are using GoTo to jump into an If…End If block somewhere in your code? I don’t know how VB pairs these up on its “stack” (a term I use casually here), but evidently it believes that you are End

    Viewing 1 reply thread
    Reply To: Compile Error when closing workbook via code (2002)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: