I am working on a vba project which essentially looks like this:
if workbooks.canCheckOut(filename) = true then
workbooks.CheckOut(filename)
set workbookVariable = workboooks.Open(filename)
else
' Pesudocode: Display error message
' Quit
end if
' Pseudocode: Do some stuff with workbookVariable.
If workbookVariable.saved = false then
workbookVariable.save
end if
If workbookVariable.canCheckIn then
workbookVariable.checkIn
Set workbookVariable = Nothing
else
msgbox "Error message goes here", vbCritical
end if
' Pseudocode: quit
(Edit: I had "If workbookVariable.Saved = True"; which was incorrect. No point in saving a file if it's already saved... So this is now updated to reflect what I really have.)
If the workbook is modified and gets saved, everything runs fine. It saves, gets checked back in to SharePoint, and the program ends normally.
However, if the workbook does not get modified, when it goes to the check back in portion of the program, excel crashes, and I get an error message: "Automation Error".
I even tried putting in a wait command after the checkIn
command, with no luck...
What is going on here? Can someone point me in the right direction?