Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    Compile Error when closing workbook via code (2002)

    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

  2. #2
    Platinum Lounger
    Join Date
    Nov 2001
    Location
    Vienna, Wien, Austria
    Posts
    5,009
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Compile Error when closing workbook via code (

    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
    Grüße

  3. #3
    3 Star Lounger
    Join Date
    Apr 2002
    Location
    Texas, USA
    Posts
    208
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Compile Error when closing workbook via code (

    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

  4. #4
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Compile Error when closing workbook via code (2002)

    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

Posting Permissions

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