Forum

Refresh windows 10 ...
 
Notifications
Clear all

Refresh windows 10 file explorer automatically

11 Posts
3 Users
0 Reactions
285 Views
(@mscheweer)
Posts: 8
Active Member
Topic starter
 

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

 
Posted : 21/06/2022 12:51 am
(@debaser)
Posts: 836
Member Moderator
 

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

 
Posted : 21/06/2022 4:33 am
(@mscheweer)
Posts: 8
Active Member
Topic starter
 

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

 
Posted : 21/06/2022 6:05 am
(@debaser)
Posts: 836
Member Moderator
 

You didn't say what the error is? Are you using 64bit Office?

 
Posted : 21/06/2022 6:38 am
(@mscheweer)
Posts: 8
Active Member
Topic starter
 

Hello Velouria,

Yes I use the 64bit Office. Below the error. (sorry for not uploading)

[Image Can Not Be Found]

 
Posted : 21/06/2022 6:50 am
(@mscheweer)
Posts: 8
Active Member
Topic starter
 

Hello Velouria,

Attached (now LaughLaughLaugh) my implementation and error.

 
Posted : 21/06/2022 7:04 am
(@debaser)
Posts: 836
Member Moderator
 

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

 
Posted : 21/06/2022 7:09 am
(@2took)
Posts: 2
New Member
 

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.

 
Posted : 20/09/2022 2:27 pm
(@debaser)
Posts: 836
Member Moderator
 

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.

 
Posted : 21/09/2022 4:31 am
(@2took)
Posts: 2
New Member
 

Is there some setting that forces MS File Explorer to refresh automatically, without VBA?

 
Posted : 22/09/2022 8:34 am
(@debaser)
Posts: 836
Member Moderator
 

Not that I'm aware of.

 
Posted : 22/09/2022 10:17 am
Share: