ThisWorkbook.Close question

  • Thread starter Thread starter Robert Crandal
  • Start date Start date
R

Robert Crandal

Please take a look at the code below:

Public Sub DumbFoo ( )
ThisWorkbook.Close()

Sheet1.Range("A1").Value = -1
ThisWorkbook.Save()
End Sub


Is it safe to assume that the code below the
"ThisWorkbook.Close()" line will NOT be
executed??? My question is basically: Does
all VBA code stop executing once a .Close()
function is called???

Thank you!
 
I don't believe the code would execute at all because of the parentheses
after Close. It would throw an error an tell you that something is missing,
or type mismatch. But, if you did have the correct syntax, without the
parentheses, then the workbook would close and no further sheet activity
would be processed and the workbook would not be saved, but you would
probably get a message asking you if you want to save the workbook.

Be careful where you put the parentheses in VBA. They usually indicate that
something is needed to complete the command or modify the object. If that
something is not included in the parentheses it throws an error.

See "Using Parentheses in Code" in the VBA help files for more details.
 
Yes, try

Public Sub DumbFoo ( )
Sheet1.Range("A1").Value = -1
ThisWorkbook.Close SaveChanges:=true
End Sub
 
Back
Top