Jon Nones
Jon Nones

Reputation: 21

VBA code in Word to check if the current macro is the most recent version

I'm creating a macro in Word 2013 to share with my org. However, I want to notify them when the macro is updated. Basically, I'd like them to run the macro, and if it finds a newer version on a network, then creates a message telling them to install the latest version.

I think the simplest solution would be to use FileDateTime("\Server\test\book1.xlsm") to check a file saved to a network, and then if newer than the current macro file, it provides a message: MsgBox "A new version of this macro exists on the network share. Please install the new version."

I know how to find if a file exists, just not how to check if it's more recent:

Sub FileExists()

    Dim FilePath As String
    Dim TestStr As String

    FilePath = "D:\FolderName\Sample.xlsx"

    TestStr = ""
    On Error Resume Next
    TestStr = Dir(FilePath)
    On Error GoTo 0
    If TestStr = "" Then
        MsgBox "File doesn't exist"
    Else
        Workbooks.Open "D:\FolderName\Sample.xlsx"
    End If

End Sub

Can anyone help piece this together?

Upvotes: 1

Views: 483

Answers (2)

Charles Kenyon
Charles Kenyon

Reputation: 1028

The macro should be stored in either the document template in which it is used or in a global template. Both can be stored on network drives. My preference is for them to be used from the local computer and a network login script set to update the local copy if changed using the old XCOPY command.

Workgroup templates are document templates managed for an enterprise or department. Global templates share resources (like macros) with all documents but are not used, themselves to create new documents.

Upvotes: 1

macropod
macropod

Reputation: 13505

You would do far better to ensure the macro is stored in the document's template, which you'd also store in a network folder where the document can access it, then simply update the template as & when required. That way:

  • the document(s) can remain in the docx format;
  • users need not be instructed to download macro updates (which I wouldn't count on them doing anyway);
  • you can always be sure the version of the macro they're running is the latest one.

Upvotes: 2

Related Questions