0

I'm trying to create a solution in Microsoft Word using VBA that automatically runs a macro after a document is saved. The goal is to check two things about the file name and take action if certain conditions are met:

  1. The file name contains specific words (e.g., "Important").
  2. The date in the file name matches today's date (in the format mm-dd-yy).

I’ve tried using Document_BeforeSave: I capture the file name before it is saved. Using Application.OnTime: I schedule the macro to run shortly after the document is saved. Checking the File Name: I want to extract the date from the file name and compare it to today's date, while also checking if certain keywords are present in the file name.

However, I am not sure if this is the most efficient or reliable method to achieve this, or if there’s a cleaner way to accomplish this in VBA. Specifically, I'm trying to ensure that the macro only runs if both conditions (specific words and matching date) are true, and it should execute after the document is saved.

I’m looking for any advice on how to effectively check file names after saving and any best practices for running macros based on file name conditions. A cleaner or more reliable method for achieving this in VBA.

Any help would be greatly appreciated!

1 Answers1

1

Create a Word Add-in using this method: How to create AfterSave event for Word document add-in which should give you the AfterSave event you're looking for.