Hello,
Some of my txt files become new content without a new date/time stamp in the windows file explorer. After pushing the F5 button the recent date/time is visible. Does anyone have some VBA code available to automate a refresh of the windows file explorer?
Kind regards
Meine
This may be a bit overkill as it refreshes the desktop too, but it's the simplest method I could think of offhand (though my windows refresh automatically if a file size changes)
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
Const SHCNE_ASSOCCHANGED As Long = &H8000000
Sub refresh_Explorer()
SHChangeNotify SHCNE_ASSOCCHANGED, &H0, 0&, 0&
End Sub
Hello Velouria,
Thanks for your answer.
I am trying to implement your suggested code into my VBA project and getting the compile error as below. I am using Office 365 and windows 10.
Do you have a suggestion how to deal with this error?
Thanks for your help anyway.
Kind regards
Meine
You didn't say what the error is? Are you using 64bit Office?
Hello Velouria,
Yes I use the 64bit Office. Below the error. (sorry for not uploading)
[Image Can Not Be Found]
Hello Velouria,
Attached (now ) my implementation and error.
Nothing attached, but for 64 bit you need to change the API declaration. This should work on 32 or 64 bit:
#If VBA7 then
Private Declare PtrSafe Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
#Else
Private Declare Function SHChangeNotify Lib "Shell32.dll" (ByVal wEventID As Long, ByVal uFlags As Long, ByVal dwItem1 As Long, ByVal dwItem2 As Long) As Long
#End If
Const SHCNE_ASSOCCHANGED As Long = &H8000000
Sub refresh_Explorer()
SHChangeNotify SHCNE_ASSOCCHANGED, &H0, 0&, 0&
End Sub
Hey @Velouria!
You said your "windows refresh automatically if a file size changes"...
Can you elaborate?
Is there some setting that forces MS File Explorer to refresh automatically, without VBA?
Is that what you've meant?
Looking for a simplest solution to have MS File Explorer to refresh when I save a file into that folder. Don't want to have to do F5 or click refresh button in order to see the file in fact been saved there. Silly, sporadic issue. I'm using macro to do the saving.
I meant exactly as I said - if I have an open Explorer window and a file changes size in the selected folder, the window updates automatically.
Is there some setting that forces MS File Explorer to refresh automatically, without VBA?
Not that I'm aware of.