Share via

Visual Basic Command to Save All Open Documents

Anonymous
2022-09-10T08:47:09+00:00

I was previously told on this help forum (https://answers.microsoft.com/en-us/msoffice/forum/all/autosaving-a-document-to-a-hard-disk-at-a/d9b7cea5-4b33-4b18-b082-5ecfd2380ddd) that the command ActiveDocument.Save can be used to save a currently open document. (This command corresponds to the Ctrl + S key shortcut.)

Does anyone know what Visual Basic command can be used to send the save command to all open documents, and not just to the one which is active?

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

9 answers

Sort by: Most helpful
  1. Anonymous
    2022-09-12T08:01:42+00:00

    Thank you for sharing your knowledge. Yes, it is expected that in modern versions of the software, various functions should work properly, especially after the developers have tested them for errors. But for some reason, this is not the case with the automatic Autorecover function, because it does not always save backup copies. Therefore, I have had to search for a better method of saving data automatically.

    If the Save function works well on all open documents simultaneously, then I will be using it without the need to add 10-second delays between saves of each document. From this help forum, I now have two scripts: One for saving backup copies in a specified location without overwriting original files, and another script for saving original files by executing the Save command. The specialists on this forum have given valuable help.

    Was this answer helpful?

    0 comments No comments
  2. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2022-09-11T18:44:28+00:00

    Well, in the old days when screen resolutions of 80 characters per line with 25 lines and written text files were stored on a flexible floppy disk, it was already known that the operating system stored the texts in blocks and these did not even have put one after the other on the data medium. And these mappings were managed by a FAT. At that time, one was still able to trace in which sector a byte was actually stored later.

    Now, before I rave about old times, what is a DOCX today? A compressed file in ZIP format, the content of which is a mix of XML code and binary data in a folder structure, which is created by several system DLL and all is passed to the OS, which buffers the data to speed up writing, and then hand over to a disk which has an NTFS structure, which in turn, as an SSD, only consists of memory modules and also has a cache and uses ECC codes and other stuff if a memory should be damaged and so the data can be restored...

    All interesting if you like reading technical articles, but you really don't have to worry about it.
    https://docs.microsoft.com/en-us/windows-server/storage/data-deduplication/overview https://docs.microsoft.com/en-us/windows-server/storage/file-server/ntfs-overview

    If you call a Save, you can be sure it works. :-)

    Andreas.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-09-11T11:05:41+00:00

    Thank you for the explanations. Apparently there is no easy way to display a message with a timeout in Microsoft Word Visual Basic.

    When the Save command is executed on each of the open documents, are they written to the hard disk simultaneously or one after another? And does Microsoft Word check the integrity of data during the saving process?

    Was this answer helpful?

    0 comments No comments
  4. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2022-09-11T09:23:57+00:00

    what commands can be used to show the message for the specified number of milliseconds?

    For example, the message “SAVING” is to be shown for 100 milliseconds.

    There is no command in VBA for that.

    You can deal with the Windows API and run into a lot of problems, because your code should be compatible with 32-bit and 64-bit Office.

    There is a Timer in VBA, but the resolution is not made for such small intervals
    https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/timer-function

    If you want to display a message then there is a way in VBA to do this while saving the files using a Userform.
    In that form we can show the filenames of each file that is currently saved.

    Here's a sample:

    https://www.dropbox.com/s/qwggg25l4myl5rt/e94679dc-78be-41bd-a639-e70488fab194.docm?dl=1

    Before you integrate this into your project, try it out first. Open a few documents, change each one by adding a space, for example, and then run the code.

    I think the time it takes to display the Userform and refresh the screen will take more time than saving the documents.

    Andreas.

    Was this answer helpful?

    0 comments No comments