3

I have a simple XML file that has the current version number of my VBA application. Upon initialization of the application, I call the GetCurrentVersionNumber() function to fetch that version number. Problem is, when I change the XML file on the server, VBA doesn't recognize it. It appears to be reading a cached version of the XML file.

Is there a way in VBA to prevent the XML file being loaded from being cached? Or, is there another workaround to this?

Here is the function:

Function GetCurrentVersionNumber() As String

    Dim doc As MSXML2.DOMDocument60
    Set doc = New MSXML2.DOMDocument60

    doc.async = False
    If Not doc.Load("http://mywebsite.com/myfile.xml") Then
        Debug.Print "Unable to retrieve current application version."
        GetCurrentVersionNumber = ""
        Exit Function
    End If
    GetCurrentVersionNumber = doc.SelectSingleNode("/Application/Version").Text

End Function

If I go to my default browser (Chrome), navigate to the the XML file, and press Shift+F5 to force reload, the VBA application gets updated thereafter.

Community
  • 1
  • 1
tomocafe
  • 1,425
  • 4
  • 20
  • 35

1 Answers1

3

One way is to append a (random) dummy querystring on the end of your URL. That will "force" a re-fetch (since URL uniqueness takes querystring into account)

Dim qs as string
qs = Cstr(rnd()*1e6)

If Not doc.Load("http://mywebsite.com/myfile.xml?" & qs) Then
...
Tim Williams
  • 154,628
  • 8
  • 97
  • 125
  • Works perfectly! I used the current time and date as the query string to enforce uniqueness. Thank you! – tomocafe Sep 11 '12 at 18:11