test if object var is set to nothing also looping through excel sh

S

SAm

hi

i have two questions. first is regarding my errors. i am trying to close the
excel spreadsheet if sub errs. I am not sure how to test the variable
MyWorkbook or MyExcelSpreadsheet.

Exit_GenerateInvoice:
Exit Sub

Err_GenerateInvoice:
MsgBox Err.Description
If (here is my question) MyWorkbook Then
MyWorkbook.Close SaveChanges:=False
MyExcelInstance.Quit
End If
Resume Exit_GenerateInvoice
End Sub

second question, (unrelated, this is more of an excel question) how to i
loop through sheets of a spreadsheet. this is my script, but it gives me
errors.

For Each sSheet In MyWorkbook
Debug.Print sSheet.Name
Next sSheet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top