Is there a way for me to revert to previous state before close? Now, if the user first in makes changes and wants to save their changes, we have no issue as the code clears the username and then saves the file. You can try worddoc.close savechanges:=wddonotsavechanges before the set worddoc = nothing also, if you want to quit the program entirely you should indeed send the command to quit it before setting the variable to nothing:
𝑩𝒖𝒃𝒂𝒍𝒖𝒖 (@iambubaluu) • Instagram photos and videos
I'm trying to add some error handling to close the document with an error message and prevent the rest of the vba from running, and i can get to the point where the document closes, but the rest of the vba code continues to execute.
You can use the documents collection to quickly close all the currently open documents
Do you want this to apply to all documents at all times, or just one specific document If you set a document's saved property to true then word will not prompt for a save on closing it, as long as there's been no change since you set that property. I have a word document with field in the end of the document to update filepath, last saved date & last save by I need these to update on the closing of the file.
Try this, savechanges:=false should close the document with no prompts and discard any changes You don't need to set doc as you use the variable in a loop code I use word 2019 + windows 10, any code that closes the document without saving changes causes word to crash (closes all open documents, reopen asking for safe mode), a simple example: However, due to network lag issues, we have to do a save in the vba code to save the user name for those who would open the file next